Skip to content

Commit

Permalink
Update poolInfoUtils.borrowerInfo to return thresholdPrice (#1017)
Browse files Browse the repository at this point in the history
* Universal deposit fee (#983)

* charge fee on all deposit

* unit tests compile

* test harness updates

* working on ERC20PoolQuoteTokenTest

* removed deposit fee cap

* more work on ERC20PoolQuoteTokenTest

* do not charge deposit fee if moving liquidity to higher price

* Eliminate reserves bad debt allocation and add margin to TP  (#962)

* this underflows instead of giving expected revert

* move isCollateralized check after updating borrower collateral

* remove local calculation of encumbered collateral

* trying to properly fix testBorrowRepayPrecision

* resolve rounding issue in fuzz test

* testCollateralization improvements

* updated unit tests for new _collateralization implementation

* more collateralization tests

* Add 1.04 factor in borrower collateralization

* Update nptp ratio to '1 + sqrt(r)/2'

* Remove Settle debt with pool reserves

* Remove 0.995 factor from claimable reserves calculation

* Update bond factor calculation to minimum 0.005

* added testcase where debt exceeds deposit

* updated test so debt exceeds deposit

* allow  up to half of current orig fee to be used to settle bad debt

* updated testTakeAndSettle

* more test fixes

* Enabled settling with all reserves if
 Deposits.treeSum==0 or 72 hrs pass

* cleanup

* Half orig fee res | Matt example (#966)

* added Matts test as proof that attack no longer works on his branch

* Revert "Remove multicall from position manager (#948)" (#961)

This reverts commit f540c8a.

* added test testSpendOrigFeePushBadDebtToBorrowers test

* cleaned up testStealReservesWithMarginm to match minted balances

* responded to Matts comments

---------

Co-authored-by: Ian Harvey <iharvey@comcast.net>
Co-authored-by: Mike Hathaway <mahathaway93@gmail.com>

* Revert "Remove Settle debt with pool reserves"

This reverts commit 290d6cf.

* Update half origination fees reserves settlement time to 144 hours from kickTime

* Fix alignment and extra spaces

* Fix some unit tests

* PR feedback

* Update encumberance and collateralization method in poolInfoUtils

* Fix some unit tests

---------

Co-authored-by: Ed Noepel <ed@noepel.net>
Co-authored-by: Ian Harvey <iharvey@comcast.net>
Co-authored-by: mwc <matt@ajna.finance>
Co-authored-by: Ian Harvey <ith.harvey@gmail.com>
Co-authored-by: Mike Hathaway <mahathaway93@gmail.com>

* Fix invariant setup

* Fix some unit tests

* ERC20PoolQuoteTokenTest updated

* updated ERC20PoolPurchaseQuoteTokenTest

* Fixed tests in ERC20PoolReserveAuction.t.sol

* updated ERC20PoolBorrowTest and ERC20PoolBorrowFuzzyTest

* Fix ERC20PoolCollateral and ERC20PoolInfoUtils tests

* Fixed ERC20 arbtake and depositTake tests

* Fix ERC20PoolLiquidationsKickTest, ERC20PoolLiquidationKickFuzzyTest and ERC20PoolLiquidationsLenderKickAuctionTest

* updated ERC20PoolMulticallTest

* cleaned up ERC20PoolDebtExceedsDepositTest

* fixed testTakeLoanColConstraintBpfPosNoResidual

* fixed testTakeCallerColConstraintBpfPosNoResidual

* fixed testTakeCallerColConstraintBpfPosResidual

* fixed testTakeCallerColConstraintBpfNegResidual

* fixed testTakeLoanDebtConstraintBpfPosResidual

* fixed testTakeAndSettle

* cleaned up ERC20PoolDebtExceedsDepositTest

* updated ERC20PoolPrecisionTest

* Update ERC20PoolLiquidationsSettleTest

* Update ERC20PoolLiquidationsMisc

* Update ERC20PoolLiquidationSettleFuzzyTest

* Update ERC20PoolLiquidationTakeFuzzyTest

* fixeed revert tests

* ERC20PoolLiquidationsTake -- fixed rest

* Mh update tests (#985)

* fix most position manager tests

* fix additional pm tests

* fix rewards requiredCollateralRewards setup

* fix ClaimRewards tests

* update additional rewards manager tests

* fix additional tests

* more test fixes

* commit wip bankruptcy tests

* fixed testMoveLiquidityToOverwriteBankruptBucket

* fix additional tests

* fix testMoveLiquidityWithDebtInPool

* fix remaining rewards manager tests

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>
Co-authored-by: mwc <matt@ajna.finance>

* Add 1.04 factor in HTP calculations (#987)

* Add 1.04 factor in HTP calculations

* Add COLLATERALIZATION_FACTOR constant in PoolHelpers

* Add collateralization factor in dwatp

* Fix poolPricesInfo

* Update ERC20PoolBorrowFuzzyTest

* Fix some unit tests

* Fix some unit tests

* Fix some unit tests

* Update ERC20PoolTransferLPs

* fix most rewards manager tests

* update remaining rewards manager tests

* update ERC721SubsetPoolBorrowTest and commit wip changes to testMergeOrRemoveERC721Collateral

* updated testSettlePartialDebtSubsetPool (#988)

* updated testSettlePartialDebtSubsetPool

* re-added teardown

---------

Co-authored-by: Ian Harvey <iharvey@comcast.net>

* fix ERC721PoolCollateral tests

* fix borrowRepayDebtFuzzy and additional PM tests

* cleaned up testBorrowAndRepayWith4DecimalQuote

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>
Co-authored-by: Ian Harvey <ith.harvey@gmail.com>
Co-authored-by: Ian Harvey <iharvey@comcast.net>

* Fix some unit tests

* Deployment updates for RC8+ releases (#986)

* cherry-picked from master

* updated README

* Fix ERC721PoolLiquidationsTakeTest

* updated ERC721PoolReserveAuctionTest

* updated testMergeOrRemoveERC721Collateral (#989)

Co-authored-by: Ian Harvey <iharvey@comcast.net>

* updated ERC721PoolPurchaseQuoteTest and fixed bug in ERC721 tearDown

* cleaned up testLiquidationLenderKickAuction, testLiquidationSingleBorrower, testSettleAuctionWithoutTakes

* updated testMoveLiquidityToOverwriteBankruptBucket

* updated PoolHelperTest

* cleaned up asserts in addLiquidity

* update testMoveLiquidityInBankruptBucket_LP_report_179_494

* updated ERC721PoolEMAsTest

* fixed testKickHighThresholdPriceBorrower

* updated testBorrowerInterestCalculationAfterRepayingAllDebtOnce and testBorrowerInterestCalculation

* updated testMultipleBorrowerInterestAccumulation

* Fix regression tests

* updated RE3, fixed _addQuoteToken

* addQuoteToken - return amount added (#993)

* addQuoteToken now returns amount added

* update unit tests to validate return values

* Fix up add liquidity (#992)

* cleaned up addLiquidity() method in ERC20PoolLiquidationsScaled.t.sol

* remove console

---------

Co-authored-by: Ian Harvey <iharvey@comcast.net>

* fixed issue with test_regression_fenwick_index_2 in non-18-decimal env

* added regression tests for two failing reserves scenarios

* rename tests such that automake runs them with other regression tests

* UnboundedLiquidationPoolHandler bucketTake fix (#994)

* updated UnboundedLiquidationPoolHandler to handle compensated collateral in bucketTake

* cleanup, trap unhandled use case

* settle event now emits actual debt settled rather than t0 amount (#999)

* settle event now emits actual debt settled rather than t0 amount

* updated test_regression_settle_with_reserves

* Updated auctionInfo (#996)

* add thresholdPrice to auctionInfo; update test iterface usages

* temp fix tests

* remove unneeded comment

* Update auction status (#998)

* wip auction status update w/ stack too deep

* update auctionStatus; add auctionInfo method to poolInfoUtils

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>

* updated brownie tests, removed obsolete invariant tests (#1001)

* Block addqt above auction price (#997)

* initial commit

* tweaks to Matt's PR to block adding quote token above auction price (#1000)

* reduce cost of reference price assignment

* reduce pool contract size

* fixed testDepositTakeAndSettleByRegularTakeSubsetPool

* fixed tests in ERC20PoolLiquidationsArbTake.t.sol

* fixed tests in ERC20PoolLiquidationsDepositTake.sol

* fixed two more

* updated testDepositTakeAndSettleSubsetPool

* updated testKickAndSettleSubsetPoolFractionalCollateral

* updated testSettleWithDepositFuzzy

* Fixed final tests

* add "AddAboveAuctionPrice" as expected pool error

* implemented invariant A9: reference prices in liquidation queue shall not decrease

* Update assertAuction to use ThresholdPrice from auctionInfo (#1003)

* use auctionInfo thresholdprice instead of recalculating

* fix most tests

* update remaining tests

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>

* Contract size mitigation (#1004)

* moved debtInfo to PoolCommons, saving 10 bytes

* moved withdrawBonds to KickerActions

* added unit test showing adding qt above auction price reverts

* updated nit spellings

---------

Co-authored-by: mwc <matt@ajna.finance>
Co-authored-by: Ed Noepel <46749157+EdNoepel@users.noreply.github.com>
Co-authored-by: Ed Noepel <ed@noepel.net>
Co-authored-by: Mike Hathaway <mahathaway93@gmail.com>
Co-authored-by: Mike <mikehathaway@makerdao.com>
Co-authored-by: Ian Harvey <iharvey@comcast.net>

* Invariant testing fixes (#1006)

* initial commit

* tweaks to Matt's PR to block adding quote token above auction price (#1000)

* reduce cost of reference price assignment

* reduce pool contract size

* fixed testDepositTakeAndSettleByRegularTakeSubsetPool

* fixed tests in ERC20PoolLiquidationsArbTake.t.sol

* fixed tests in ERC20PoolLiquidationsDepositTake.sol

* fixed two more

* updated testDepositTakeAndSettleSubsetPool

* updated testKickAndSettleSubsetPoolFractionalCollateral

* updated testSettleWithDepositFuzzy

* Fixed final tests

* add "AddAboveAuctionPrice" as expected pool error

* implemented invariant A9: reference prices in liquidation queue shall not decrease

* Update assertAuction to use ThresholdPrice from auctionInfo (#1003)

* use auctionInfo thresholdprice instead of recalculating

* fix most tests

* update remaining tests

---------

Co-authored-by: Mike <mikehathaway@makerdao.com>

* Contract size mitigation (#1004)

* moved debtInfo to PoolCommons, saving 10 bytes

* moved withdrawBonds to KickerActions

* documented a sample of invariant failures in regression tests

* added unit test showing adding qt above auction price reverts

* fixed _isCollateralized bug not returning true in all 0-debt use cases

* updated nit spellings

* fixed underflow calculating kicker reward

* _repayDebtByThirdParty should check for expected pool errors

* Round down when reward kicker, round up when kicker is penalized
Fix roundings in tests

* update test comments

* fix and enable A9 invariant

---------

Co-authored-by: mwc <matt@ajna.finance>
Co-authored-by: Mike Hathaway <mahathaway93@gmail.com>
Co-authored-by: Mike <mikehathaway@makerdao.com>
Co-authored-by: Ian Harvey <iharvey@comcast.net>
Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>

* RC9 suggested improvements (#1005)

* Revert AuctionNotTakeable in same place, load auction kickTime only once from storage

* Calculate ERC721 collateralTaken only once
cosmetize code (read from result struct in local var and reuse)
Results in shrinking a little bit contract sizes

* Read borrower Np Tp ratio from storage only once when kick

* If block style, proper indentation

* Proposed changes to PR #972:
- avoid calculating current LUP twice in lender kick
- change _kick function to accept proposed LUP (for regular kick proposed LUP is current LUP, for lender kick proposed LUP is calculated based on additional debt)
- in both kick cases return current LUP in kick result
- reduce gas costs by saving a Fenwick traversal
- reduce contract size by removing LUP calculation within Pool

* Cosmetic flashloan code changes, PoolCommons.flashLoan doesn't return false but always reverts if flashloan fails

* PR#983 style, remove redundant line

* PR#999 suggested improvement - calculate current settled debt only once and include in settle result for state update

* PR #962 proposed changes:
- get Fenwick deposits only once when settle with reserves
- define constants for min bond factor and max npTp ratio values

* PR #987 proposed improvement:
- add and reuse _htp helper function (instead duplicated maths)

* Continuation of PR #962: (#1008)

- Record settle amount limmit in Liquidtion struct, at the time of kick (that is instead incrementing accumulator in Borrower struct, each time debt is drawn)
- This way accumulator will be reseted when auction is settled
- fix tests

TODO:
- assert Liquidation.t0ReserveSettleAmount in unit tests (_assertAuction), make sure is set to 0 after auction settled and decreased when partial settles done
- update invariant test to check new introduced accumulator

* Misc test fixes (#1009)

* handle another reward rounding error use case

* fix intermittant fuzz test failure - cannot draw debt from liquidity in bucket 7388

* PositionManager should expect AddAboveAuctionPrice, which can happen in moveLiquidity

* Invariant fix: round up quote tokens calculated from rewarded LP (because LP rewarded are calculated in bucketTake as rewarded quote tokens -> LP rounded down)

* Pr feedback

* Fix failing unit tests

* update poolInfoUtils.borrowerInfo interface

* return thresholdPrice instead of t0ThresholdPrice

* fix compile warnings

* update borrowerInfo threshold price references

* resolved comments on borrowerInfo

---------

Co-authored-by: Ed Noepel <46749157+EdNoepel@users.noreply.github.com>
Co-authored-by: Prateek Gupta <prateek105@users.noreply.github.com>
Co-authored-by: Ed Noepel <ed@noepel.net>
Co-authored-by: Ian Harvey <iharvey@comcast.net>
Co-authored-by: mwc <matt@ajna.finance>
Co-authored-by: Ian Harvey <ith.harvey@gmail.com>
Co-authored-by: prateek105 <prateek@ajna.finance>
Co-authored-by: Mike <mikehathaway@makerdao.com>
Co-authored-by: mattcushman <36414299+mattcushman@users.noreply.github.com>
Co-authored-by: grandizzy <grandizzy.the.egg@gmail.com>
Co-authored-by: grandizzy <38490174+grandizzy@users.noreply.github.com>
  • Loading branch information
12 people authored Dec 19, 2023
1 parent f7bc7dc commit f23c988
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 90 deletions.
18 changes: 10 additions & 8 deletions src/PoolInfoUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract PoolInfoUtils {
debtToCollateral_, , , ) = IPool(ajnaPool_).auctionInfo(borrower_);

if (kickTime_ != 0) {
(debtToCover_, collateral_, ) = this.borrowerInfo(ajnaPool_, borrower_);
(debtToCover_, collateral_, , ) = this.borrowerInfo(ajnaPool_, borrower_);

(vars.poolDebt,,,) = IPool(ajnaPool_).debtInfo();
vars.lup = _priceAt(IPool(ajnaPool_).depositIndex(vars.poolDebt));
Expand Down Expand Up @@ -128,19 +128,21 @@ contract PoolInfoUtils {

/**
* @notice Retrieves info of a given borrower in a given `Ajna` pool.
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Borrower's address.
* @return debt_ Current debt owed by borrower (`WAD`).
* @return collateral_ Pledged collateral, including encumbered (`WAD`).
* @return t0Np_ `Neutral price` (`WAD`).
* @param ajnaPool_ Address of `Ajna` pool.
* @param borrower_ Borrower's address.
* @return debt_ Current debt owed by borrower (`WAD`).
* @return collateral_ Pledged collateral, including encumbered (`WAD`).
* @return t0Np_ `Neutral price` (`WAD`).
* @return thresholdPrice_ Borrower's `Threshold Price` (`WAD`).
*/
function borrowerInfo(address ajnaPool_, address borrower_)
external
view
returns (
uint256 debt_,
uint256 collateral_,
uint256 t0Np_
uint256 t0Np_,
uint256 thresholdPrice_
)
{
IPool pool = IPool(ajnaPool_);
Expand All @@ -159,8 +161,8 @@ contract PoolInfoUtils {
(t0Debt, collateral_, npTpRatio) = pool.borrowerInfo(borrower_);

t0Np_ = collateral_ == 0 ? 0 : Math.mulDiv(Maths.wmul(t0Debt, COLLATERALIZATION_FACTOR), npTpRatio, collateral_);

debt_ = Maths.ceilWmul(t0Debt, pendingInflator);
thresholdPrice_ = collateral_ == 0 ? 0 : Maths.wmul(Maths.wdiv(debt_, collateral_), COLLATERALIZATION_FACTOR);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/brownie/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def availableLiquidity(self):
return quoteBalance - reserves;

def borrowerInfo(self, borrower_address):
# returns (debt, collateral, t0NeutralPrice)
# returns (debt, collateral, t0NeutralPrice, thresholdPrice)
return self.pool_info_utils.borrowerInfo(self.pool.address, borrower_address)

def bucketInfo(self, index):
Expand Down Expand Up @@ -375,7 +375,7 @@ def validate_pool(pool_helper, borrowers):

borrowers_with_debt = 0
for borrower in borrowers:
(debt, _, _) = pool_helper.borrowerInfo(borrower.address)
(debt, _, _, _) = pool_helper.borrowerInfo(borrower.address)
if debt > 0:
borrowers_with_debt += 1
assert borrowers_with_debt == loansCount
Expand Down
6 changes: 3 additions & 3 deletions tests/brownie/test_stable_volatile.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def aggregate_borrower_debt(borrowers, pool_helper, debug=False):
total_debt = 0
for i in range(0, len(borrowers) - 1):
borrower = borrowers[i]
(debt, _, _) = pool_helper.borrowerInfo(borrower.address)
(debt, _, _, _) = pool_helper.borrowerInfo(borrower.address)
if debug and debt > 0:
log(f" borrower {i:>4} debt: {debt/1e18:>15.3f}")
total_debt += debt
Expand All @@ -177,7 +177,7 @@ def pledge_and_borrow(pool_helper, borrower, borrower_index, collateral_to_depos
pool = pool_helper.pool

# prevent invalid actions
(debt, pledged, _) = pool_helper.borrowerInfo(borrower.address)
(debt, pledged, _, _) = pool_helper.borrowerInfo(borrower.address)
if not ensure_pool_is_funded(pool, borrow_amount, "borrow"):
# ensure_pool_is_funded logs a message
return
Expand Down Expand Up @@ -320,7 +320,7 @@ def remove_quote_token(lender, lender_index, price, pool_helper) -> bool:

def repay_debt(borrower, borrower_index, pool_helper, test_utils):
dai = pool_helper.quoteToken()
(debt, collateral_deposited, _) = pool_helper.borrowerInfo(borrower)
(debt, collateral_deposited, _, _) = pool_helper.borrowerInfo(borrower)
quote_balance = dai.balanceOf(borrower)
(_, _, _, min_debt) = pool_helper.utilizationInfo()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract contract BaseHandler is Test {
uint256 collateral;
uint256 npTpRatio;
uint256 t0Np;
uint256 thresholdPrice;
}

struct BucketInfo {
Expand Down Expand Up @@ -349,7 +350,8 @@ abstract contract BaseHandler is Test {
(
borrowerInfo_.debt,
borrowerInfo_.collateral,
borrowerInfo_.t0Np
borrowerInfo_.t0Np,
borrowerInfo_.thresholdPrice
) = _poolInfo.borrowerInfo(address(_pool), borrower_);

(
Expand Down Expand Up @@ -735,6 +737,9 @@ abstract contract BaseHandler is Test {
if (borrowerInfo.debt != 0 || borrowerInfo.collateral != 0) {
printLog("Debt = ", borrowerInfo.debt);
printLog("Pledged collateral = ", borrowerInfo.collateral);
printLog("t0 Neutral Price = ", borrowerInfo.t0Np);
printLog("Threshold Price = ", borrowerInfo.thresholdPrice);

}
}
printInNextLine("=======================");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ERC20PoolBorrowerTPLessThanMinPrice is ERC20HelperContract {
newLup: 3_010.892022197881557845 * 1e18
});

(uint256 debt, uint256 collateral, ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
(uint256 debt, uint256 collateral, , ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
uint256 debtToCollateral = Maths.wdiv(debt, collateral);

// Ensure borrower tp is less than min price
Expand Down
2 changes: 1 addition & 1 deletion tests/forge/unit/ERC20Pool/ERC20DSTestPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract contract ERC20DSTestPlus is DSTestPlus, IERC20PoolEvents {

uint256 pledgedCollateral = 0;
for (uint i = 0; i < borrowers.length(); i++) {
(, uint256 collateral,) = _poolUtils.borrowerInfo(address(_pool), borrowers.at(i));
(, uint256 collateral, , ) = _poolUtils.borrowerInfo(address(_pool), borrowers.at(i));
pledgedCollateral += collateral;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/forge/unit/ERC20Pool/ERC20PoolBorrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ contract ERC20PoolBorrowFuzzyTest is ERC20FuzzyHelperContract {
}

// check borrower info
(uint256 debt, , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));
(uint256 debt, , , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));
assertGt(debt, borrowAmount); // check that initial fees accrued

// check pool state
Expand Down Expand Up @@ -1338,7 +1338,7 @@ contract ERC20PoolBorrowFuzzyTest is ERC20FuzzyHelperContract {
skip(1 days);

// repay all debt and withdraw collateral
(debt, , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));
(debt, , , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));

deal(address(_quote), _borrower, debt);

Expand Down Expand Up @@ -1376,7 +1376,7 @@ contract ERC20PoolBorrowFuzzyTest is ERC20FuzzyHelperContract {
}

// check borrower state after repayment
(debt, , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));
(debt, , , ) = _poolUtils.borrowerInfo(address(_pool), address(_borrower));
assertEq(debt, 0);

// check pool state
Expand Down
4 changes: 2 additions & 2 deletions tests/forge/unit/ERC20Pool/ERC20PoolGasLoadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ contract ERC20PoolCommonActionsGasLoadTest is ERC20PoolGasLoadTest {
skip(15 hours);

address borrower = _borrowers[borrowerId_];
(uint256 debt, , ) = _poolUtils.borrowerInfo(address(_pool), borrower);
(uint256 debt, , , ) = _poolUtils.borrowerInfo(address(_pool), borrower);

vm.prank(borrower);
ERC20Pool(address(_pool)).repayDebt(borrower, debt, 0, borrower, MAX_FENWICK_INDEX);
Expand Down Expand Up @@ -220,7 +220,7 @@ contract ERC20PoolCommonActionsGasLoadTest is ERC20PoolGasLoadTest {
assertEq(_noOfLoans(), LOANS_COUNT);

address borrower = _borrowers[i];
(uint256 debt, , ) = _poolUtils.borrowerInfo(address(_pool), borrower);
(uint256 debt, , , ) = _poolUtils.borrowerInfo(address(_pool), borrower);

vm.prank(borrower);
ERC20Pool(address(_pool)).repayDebt(borrower, debt, 0, borrower, MAX_FENWICK_INDEX);
Expand Down
87 changes: 44 additions & 43 deletions tests/forge/unit/ERC20Pool/ERC20PoolInfoUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ contract ERC20PoolInfoUtilsTest is ERC20HelperContract {
uint256 price,
uint256 neutralPrice,
uint256 referencePrice,
uint256 thresholdPrice,
uint256 debtToCollateral,
uint256 bondFactor
) = _poolUtils.auctionStatus(address(_pool), _borrower);
// since loan is not in auction values are 0
assertEq(kickTime, 0);
assertEq(collateral, 0);
assertEq(debtToCover, 0);
assertEq(kickTime, 0);
assertEq(collateral, 0);
assertEq(debtToCover, 0);
assertEq(isCollateralized, false);
assertEq(price, 0);
assertEq(neutralPrice, 0);
assertEq(referencePrice, 0);
assertEq(thresholdPrice, 0);
assertEq(bondFactor, 0);
assertEq(price, 0);
assertEq(neutralPrice, 0);
assertEq(referencePrice, 0);
assertEq(debtToCollateral, 0);
assertEq(bondFactor, 0);
}

function testPoolInfoUtilsAuctionStatusMatureLiquidation() external {
Expand All @@ -129,19 +129,19 @@ contract ERC20PoolInfoUtilsTest is ERC20HelperContract {
uint256 price,
uint256 neutralPrice,
uint256 referencePrice,
uint256 thresholdPrice,
uint256 debtToCollateral,
uint256 bondFactor
) = _poolUtils.auctionStatus(address(_pool), _borrower);
// at 6 hours, auction price should match reference price
assertEq(kickTime, _startTime);
assertEq(collateral, 100 * 1e18);
assertEq(debtToCover, 21_020.912189618561131155 * 1e18);
assertEq(isCollateralized, true);
assertEq(price, 243.051341028061451208 * 1e18);
assertEq(neutralPrice, 243.051341028061451209 * 1e18);
assertEq(referencePrice, 243.051341028061451209 * 1e18);
assertEq(thresholdPrice, 210.201923076923077020 * 1e18);
assertEq(bondFactor, 0.011180339887498948 * 1e18);
assertEq(kickTime, _startTime);
assertEq(collateral, 100 * 1e18);
assertEq(debtToCover, 21_020.912189618561131155 * 1e18);
assertEq(isCollateralized, true);
assertEq(price, 243.051341028061451208 * 1e18);
assertEq(neutralPrice, 243.051341028061451209 * 1e18);
assertEq(referencePrice, 243.051341028061451209 * 1e18);
assertEq(debtToCollateral, 210.201923076923077020 * 1e18);
assertEq(bondFactor, 0.011180339887498948 * 1e18);
}


Expand All @@ -153,22 +153,22 @@ contract ERC20PoolInfoUtilsTest is ERC20HelperContract {
uint256 kickTime,
uint256 referencePrice,
uint256 neutralPrice,
uint256 thresholdPrice,
uint256 debtToCollateral,
address head,
address next,
address prev
) = _poolUtils.auctionInfo(address(_pool), _borrower);
// since loan is not in auction values are 0
assertEq(kicker, address(0));
assertEq(bondFactor, 0);
assertEq(bondSize, 0);
assertEq(kickTime, 0);
assertEq(referencePrice, 0);
assertEq(neutralPrice, 0);
assertEq(thresholdPrice, 0);
assertEq(head, address(0));
assertEq(next, address(0));
assertEq(prev, address(0));
assertEq(kicker, address(0));
assertEq(bondFactor, 0);
assertEq(bondSize, 0);
assertEq(kickTime, 0);
assertEq(referencePrice, 0);
assertEq(neutralPrice, 0);
assertEq(debtToCollateral, 0);
assertEq(head, address(0));
assertEq(next, address(0));
assertEq(prev, address(0));
}

function testPoolInfoUtilsAuctionInfoSingleLiquidation() external {
Expand All @@ -180,27 +180,28 @@ contract ERC20PoolInfoUtilsTest is ERC20HelperContract {
uint256 kickTime,
uint256 referencePrice,
uint256 neutralPrice,
uint256 thresholdPrice,
uint256 debtToCollateral,
address head,
address next,
address prev
) = _poolUtils.auctionInfo(address(_pool), _borrower);
assertEq(kicker, _lender);
assertEq(bondFactor, 0.011180339887498948 * 1e18);
assertEq(bondSize, 235.012894500590867635 * 1e18);
assertEq(kickTime, _startTime);
assertEq(referencePrice, 243.051341028061451209 * 1e18);
assertEq(neutralPrice, 243.051341028061451209 * 1e18);
assertEq(thresholdPrice, 210.201923076923077020 * 1e18);
assertEq(head, _borrower);
assertEq(next, address(0));
assertEq(prev, address(0));
assertEq(kicker, _lender);
assertEq(bondFactor, 0.011180339887498948 * 1e18);
assertEq(bondSize, 235.012894500590867635 * 1e18);
assertEq(kickTime, _startTime);
assertEq(referencePrice, 243.051341028061451209 * 1e18);
assertEq(neutralPrice, 243.051341028061451209 * 1e18);
assertEq(debtToCollateral, 210.201923076923077020 * 1e18);
assertEq(head, _borrower);
assertEq(next, address(0));
assertEq(prev, address(0));
}

function testPoolInfoUtilsBorrowerInfo() external {
(uint256 debt, uint256 collateral, uint256 npTpRatio) = _poolUtils.borrowerInfo(address(_pool), _borrower);
(uint256 debt, uint256 collateral, uint256 npTpRatio, uint256 thresholdPrice) = _poolUtils.borrowerInfo(address(_pool), _borrower);
assertEq(debt, 21_020.192307692307702000 * 1e18);
assertEq(collateral, 100 * 1e18);
assertEq(thresholdPrice, 218.610000000000000101 * 1e18);
assertEq(npTpRatio, 243.051341028061451209 * 1e18);
}

Expand Down Expand Up @@ -409,7 +410,7 @@ contract ERC20PoolInfoUtilsTest is ERC20HelperContract {

bytes[] memory result = poolUtilsMulticall.multicall(functionSignatures, args);

(uint256 debt,,) = abi.decode(result[0], (uint256, uint256, uint256));
(uint256 debt,,,) = abi.decode(result[0], (uint256, uint256, uint256, uint256));

assertEq(debt, 21_020.192307692307702000 * 1e18);
assertEq(abi.decode(result[1], (uint256)), _poolUtils.htp(address(_pool)));
Expand Down
4 changes: 2 additions & 2 deletions tests/forge/unit/ERC20Pool/ERC20PoolInterestRateAndEMAs.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract {
skip(1 days);

// check borrower collateralization and pledge more collateral if undercollateralized
(uint256 debt, uint256 collateralPledged, ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
(uint256 debt, uint256 collateralPledged, , ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
uint256 requiredCollateral = _requiredCollateral(debt, _lupIndex());

if (requiredCollateral > collateralPledged ) {
Expand Down Expand Up @@ -1387,7 +1387,7 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract {
// stop pledging more collateral to avoid t0Tp becoming 0, i = 103 is the limit where t0tp becomes 0
if (i < 100) {
// check borrower collateralization and pledge more collateral if undercollateralized to avoid `(((tu + mau102 - 1e18) / 1e9) ** 2)` overflow
(uint256 debt, uint256 collateralPledged, ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
(uint256 debt, uint256 collateralPledged, , ) = _poolUtils.borrowerInfo(address(_pool), _borrower);
(uint256 poolDebt,,,) = _pool.debtInfo();
uint256 lupIndex = _pool.depositIndex(poolDebt);
uint256 requiredCollateral = _requiredCollateral(debt, lupIndex);
Expand Down
2 changes: 1 addition & 1 deletion tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKick.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ contract ERC20PoolLiquidationKickFuzzyTest is ERC20FuzzyHelperContract {

uint256 borrowerDebt = Maths.wmul(amountToBorrow, _poolUtils.borrowFeeRate(address(_pool)) + Maths.WAD);

(,, uint256 borrowert0Np) = _poolUtils.borrowerInfo(address(_pool), _borrowers[i]);
(,, uint256 borrowert0Np, ) = _poolUtils.borrowerInfo(address(_pool), _borrowers[i]);

uint256 lup = _poolUtils.lup(address(_pool));

Expand Down
Loading

0 comments on commit f23c988

Please sign in to comment.