Skip to content

Commit

Permalink
Continuation of #1021 - better naming and improved code descriptions
Browse files Browse the repository at this point in the history
- change Loan.thresholdPrice and Liquidation.thresholdPrice to unadjustedThresholdPrice naming in order to reflect Collateral factor not applied to these values
- reflect in var names where max unadjusted threshold price is used (Move/Remove param struct)
- natspec update

- rename MAX_NP_TP_RATIO to MAX_BOND_FACTOR
  • Loading branch information
grandizzy committed Dec 12, 2023
1 parent e258a84 commit 1091a3d
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 150 deletions.
52 changes: 26 additions & 26 deletions src/PoolInfoUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ contract PoolInfoUtils {

/**
* @notice Exposes status of a liquidation auction.
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Identifies the loan being liquidated.
* @return kickTime_ Time auction was kicked, implying end time.
* @return collateral_ Remaining collateral available to be purchased. (`WAD`)
* @return debtToCover_ Borrower debt to be covered. (`WAD`)
* @return isCollateralized_ `True` if loan is collateralized.
* @return price_ Current price of the auction. (`WAD`)
* @return neutralPrice_ Price at which bond holder is neither rewarded nor penalized. (`WAD`)
* @return referencePrice_ Price used to determine auction start price. (`WAD`)
* @return thresholdPrice_ Threshold Price when liquidation was started. (`WAD`)
* @return bondFactor_ The factor used for calculating bond size. (`WAD`)
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Identifies the loan being liquidated.
* @return kickTime_ Time auction was kicked, implying end time.
* @return collateral_ Remaining collateral available to be purchased. (`WAD`)
* @return debtToCover_ Borrower debt to be covered. (`WAD`)
* @return isCollateralized_ `True` if loan is collateralized.
* @return price_ Current price of the auction. (`WAD`)
* @return neutralPrice_ Price at which bond holder is neither rewarded nor penalized. (`WAD`)
* @return referencePrice_ Price used to determine auction start price. (`WAD`)
* @return unadjustedThresholdPrice_ Unadjusted threshold Price (`debt / collateral`). (`WAD`)
* @return bondFactor_ The factor used for calculating bond size. (`WAD`)
*/
function auctionStatus(address ajnaPool_, address borrower_)
external
Expand All @@ -70,7 +70,7 @@ contract PoolInfoUtils {
uint256 price_,
uint256 neutralPrice_,
uint256 referencePrice_,
uint256 thresholdPrice_,
uint256 unadjustedThresholdPrice_,
uint256 bondFactor_
)
{
Expand All @@ -81,7 +81,7 @@ contract PoolInfoUtils {
kickTime_,
referencePrice_,
neutralPrice_,
thresholdPrice_, , , ) = IPool(ajnaPool_).auctionInfo(borrower_);
unadjustedThresholdPrice_, , , ) = IPool(ajnaPool_).auctionInfo(borrower_);

if (kickTime_ != 0) {
(debtToCover_, collateral_, ) = this.borrowerInfo(ajnaPool_, borrower_);
Expand All @@ -97,18 +97,18 @@ contract PoolInfoUtils {
/**
* @notice Returns details of an auction for a given borrower address.
* @dev Calls and returns all values from pool.auctionInfo().
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Address of the borrower that is liquidated.
* @return kicker_ Address of the kicker that is kicking the auction.
* @return bondFactor_ The factor used for calculating bond size.
* @return bondSize_ The bond amount in quote token terms.
* @return kickTime_ Time the liquidation was initiated.
* @return referencePrice_ Price used to determine auction start price.
* @return neutralPrice_ `Neutral Price` of auction.
* @return thresholdPrice_ Threshold Price when liquidation was started.
* @return head_ Address of the head auction.
* @return next_ Address of the next auction in queue.
* @return prev_ Address of the prev auction in queue.
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Address of the borrower that is liquidated.
* @return kicker_ Address of the kicker that is kicking the auction.
* @return bondFactor_ The factor used for calculating bond size.
* @return bondSize_ The bond amount in quote token terms.
* @return kickTime_ Time the liquidation was initiated.
* @return referencePrice_ Price used to determine auction start price.
* @return neutralPrice_ `Neutral Price` of auction.
* @return unadjustedThresholdPrice_ Unadjusted threshold Price (`debt / collateral`), which is used in BPF for kicker's reward calculation.
* @return head_ Address of the head auction.
* @return next_ Address of the next auction in queue.
* @return prev_ Address of the prev auction in queue.
*/
function auctionInfo(address ajnaPool_, address borrower_) external view returns (
address kicker_,
Expand All @@ -117,7 +117,7 @@ contract PoolInfoUtils {
uint256 kickTime_,
uint256 referencePrice_,
uint256 neutralPrice_,
uint256 thresholdPrice_,
uint256 unadjustedThresholdPrice_,
address head_,
address next_,
address prev_
Expand Down
24 changes: 12 additions & 12 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
_revertIfAuctionDebtLocked(deposits, poolState.t0DebtInAuction, fromIndex_, poolState.inflator);

MoveQuoteParams memory moveParams;
moveParams.maxAmountToMove = maxAmount_;
moveParams.fromIndex = fromIndex_;
moveParams.toIndex = toIndex_;
moveParams.thresholdPrice = Loans.getMax(loans).thresholdPrice;
moveParams.maxAmountToMove = maxAmount_;
moveParams.fromIndex = fromIndex_;
moveParams.toIndex = toIndex_;
moveParams.maxUnadjustedThresholdPrice = Loans.getMax(loans).unadjustedThresholdPrice;

uint256 newLup;
(
Expand Down Expand Up @@ -247,9 +247,9 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
deposits,
poolState,
RemoveQuoteParams({
maxAmount: Maths.min(maxAmount_, _availableQuoteToken()),
index: index_,
thresholdPrice: Loans.getMax(loans).thresholdPrice
maxAmount: Maths.min(maxAmount_, _availableQuoteToken()),
index: index_,
maxUnadjustedThresholdPrice: Loans.getMax(loans).unadjustedThresholdPrice
})
);

Expand Down Expand Up @@ -559,7 +559,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
emaState,
deposits,
poolState_,
Loans.getMax(loans).thresholdPrice,
Loans.getMax(loans).unadjustedThresholdPrice,
elapsed
) returns (uint256 newInflator, uint256 newInterest) {
poolState_.inflator = newInflator;
Expand Down Expand Up @@ -739,7 +739,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
uint256 kickTime_,
uint256 referencePrice_,
uint256 neutralPrice_,
uint256 thresholdPrice_,
uint256 unadjustedThresholdPrice_,
address head_,
address next_,
address prev_
Expand All @@ -752,7 +752,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
liquidation.kickTime,
liquidation.referencePrice,
liquidation.neutralPrice,
liquidation.thresholdPrice,
liquidation.unadjustedThresholdPrice,
auctions.head,
liquidation.next,
liquidation.prev
Expand Down Expand Up @@ -911,7 +911,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
Loan memory loan = Loans.getByIndex(loans, loanId_);
return (
loan.borrower,
Maths.wmul(loan.thresholdPrice, COLLATERALIZATION_FACTOR)
Maths.wmul(loan.unadjustedThresholdPrice, COLLATERALIZATION_FACTOR)
);
}

Expand All @@ -920,7 +920,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
Loan memory maxLoan = Loans.getMax(loans);
return (
maxLoan.borrower,
_htp(maxLoan.thresholdPrice, inflatorState.inflator),
_htp(maxLoan.unadjustedThresholdPrice, inflatorState.inflator),
Loans.noOfLoans(loans)
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/pool/commons/IPoolInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ struct AddQuoteParams {

/// @dev Struct used to hold parameters for `LenderAction.moveQuoteToken` action.
struct MoveQuoteParams {
uint256 fromIndex; // the deposit index from where amount is moved
uint256 maxAmountToMove; // [WAD] max amount to move between deposits
uint256 toIndex; // the deposit index where amount is moved to
uint256 thresholdPrice; // [WAD] max threshold price in pool
uint256 fromIndex; // the deposit index from where amount is moved
uint256 maxAmountToMove; // [WAD] max amount to move between deposits
uint256 toIndex; // the deposit index where amount is moved to
uint256 maxUnadjustedThresholdPrice; // [WAD] max unadjusted threshold price in pool
}

/// @dev Struct used to hold parameters for `LenderAction.removeQuoteToken` action.
struct RemoveQuoteParams {
uint256 index; // the deposit index from where amount is removed
uint256 maxAmount; // [WAD] max amount to be removed
uint256 thresholdPrice; // [WAD] max threshold price in pool
uint256 index; // the deposit index from where amount is removed
uint256 maxAmount; // [WAD] max amount to be removed
uint256 maxUnadjustedThresholdPrice; // [WAD] max unadjusted threshold price in pool
}

/*************************************/
Expand Down
58 changes: 29 additions & 29 deletions src/interfaces/pool/commons/IPoolState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ interface IPoolState {

/**
* @notice Returns details of an auction for a given borrower address.
* @param borrower_ Address of the borrower that is liquidated.
* @return kicker_ Address of the kicker that is kicking the auction.
* @return bondFactor_ The factor used for calculating bond size.
* @return bondSize_ The bond amount in quote token terms.
* @return kickTime_ Time the liquidation was initiated.
* @return referencePrice_ Price used to determine auction start price.
* @return neutralPrice_ `Neutral Price` of auction.
* @return thresholdPrice_ Threshold Price when liquidation was started.
* @return head_ Address of the head auction.
* @return next_ Address of the next auction in queue.
* @return prev_ Address of the prev auction in queue.
* @param borrower_ Address of the borrower that is liquidated.
* @return kicker_ Address of the kicker that is kicking the auction.
* @return bondFactor_ The factor used for calculating bond size.
* @return bondSize_ The bond amount in quote token terms.
* @return kickTime_ Time the liquidation was initiated.
* @return referencePrice_ Price used to determine auction start price.
* @return neutralPrice_ `Neutral Price` of auction.
* @return unadjustedThresholdPrice_ Unadjusted threshold Price (`debt / collateral`), which is used in BPF for kicker's reward calculation.
* @return head_ Address of the head auction.
* @return next_ Address of the next auction in queue.
* @return prev_ Address of the prev auction in queue.
*/
function auctionInfo(address borrower_)
external
Expand All @@ -31,7 +31,7 @@ interface IPoolState {
uint256 kickTime_,
uint256 referencePrice_,
uint256 neutralPrice_,
uint256 thresholdPrice_,
uint256 unadjustedThresholdPrice_,
address head_,
address next_,
address prev_
Expand Down Expand Up @@ -200,9 +200,9 @@ interface IPoolState {

/**
* @notice Returns information about a loan in the pool.
* @param loanId_ Loan's id within loan heap. Max loan is position `1`.
* @return borrower_ Borrower address at the given position.
* @return t0ThresholdPrice_ Borrower t0 threshold price in pool.
* @param loanId_ Loan's id within loan heap. Max loan is position `1`.
* @return borrower_ Borrower address at the given position.
* @return thresholdPrice_ Borrower threshold price in pool (including the collateralization factor).
*/
function loanInfo(
uint256 loanId_
Expand All @@ -211,13 +211,13 @@ interface IPoolState {
view
returns (
address borrower_,
uint256 t0ThresholdPrice_
uint256 thresholdPrice_
);

/**
* @notice Returns information about pool loans.
* @return maxBorrower_ Borrower address with highest threshold price.
* @return maxThresholdPrice_ Highest threshold price in pool.
* @return maxThresholdPrice_ Highest threshold price in pool (including the collateralization factor).
* @return noOfLoans_ Total number of loans.
*/
function loansInfo()
Expand Down Expand Up @@ -380,8 +380,8 @@ struct LoansState {

/// @dev Struct holding loan state.
struct Loan {
address borrower; // borrower address
uint96 thresholdPrice; // [WAD] Loan's threshold price.
address borrower; // borrower address
uint96 unadjustedThresholdPrice; // [WAD] Loan's unadjusted threshold price (`debt / collateral`).
}

/// @dev Struct holding borrower state.
Expand All @@ -407,16 +407,16 @@ struct AuctionsState {

/// @dev Struct holding liquidation state.
struct Liquidation {
address kicker; // address that initiated liquidation
uint96 bondFactor; // [WAD] bond factor used to start liquidation
uint96 kickTime; // timestamp when liquidation was started
address prev; // previous liquidated borrower in auctions queue
uint96 referencePrice; // [WAD] used to calculate auction start price
address next; // next liquidated borrower in auctions queue
uint160 bondSize; // [WAD] liquidation bond size
uint96 neutralPrice; // [WAD] Neutral Price when liquidation was started
uint256 thresholdPrice; // [WAD] Threshold Price when liquidation was started
uint256 t0ReserveSettleAmount; // [WAD] Amount of t0Debt that could be settled via reserves in this auction
address kicker; // address that initiated liquidation
uint96 bondFactor; // [WAD] bond factor used to start liquidation
uint96 kickTime; // timestamp when liquidation was started
address prev; // previous liquidated borrower in auctions queue
uint96 referencePrice; // [WAD] used to calculate auction start price
address next; // next liquidated borrower in auctions queue
uint160 bondSize; // [WAD] liquidation bond size
uint96 neutralPrice; // [WAD] Neutral Price when liquidation was started
uint256 unadjustedThresholdPrice; // [WAD] Unadjusted threshold Price (`debt / collateral`), which is used in BPF for kicker's reward calculation
uint256 t0ReserveSettleAmount; // [WAD] Amount of t0Debt that could be settled via reserves in this auction
}

/// @dev Struct holding kicker state.
Expand Down
Loading

0 comments on commit 1091a3d

Please sign in to comment.