Skip to content

Commit

Permalink
Reorg code and revert, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Jun 14, 2023
1 parent e98167b commit 586c305
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
17 changes: 9 additions & 8 deletions src/libraries/external/KickerActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,19 @@ library KickerActions {
) external returns (
KickResult memory kickResult_
) {
KickWithDepositLocalVars memory vars;

vars.bucketPrice = _priceAt(index_);
vars.currentLup = Deposits.getLup(deposits_, poolState_.debt);

// revert if the bucket price is below LUP
if (vars.bucketPrice < vars.currentLup) revert PriceBelowLUP();

Bucket storage bucket = buckets_[index_];
Lender storage lender = bucket.lenders[msg.sender];

KickWithDepositLocalVars memory vars;

vars.lenderLP = bucket.bankruptcyTime < lender.depositTime ? lender.lps : 0;
vars.bucketDeposit = Deposits.valueAt(deposits_, index_);
vars.bucketPrice = _priceAt(index_);
vars.currentLup = Deposits.getLup(deposits_, poolState_.debt);

// revert if the bucket price used to kick and remove is below LUP
if (vars.bucketPrice < vars.currentLup) revert PriceBelowLUP();

// calculate amount lender is entitled in current bucket (based on lender LP in bucket)
vars.entitledAmount = Buckets.lpToQuoteTokens(
Expand All @@ -183,7 +184,7 @@ library KickerActions {
// revert if no entitled amount
if (vars.entitledAmount == 0) revert InsufficientLiquidity();

// kick borrower
// kick top borrower
kickResult_ = _kick(
auctions_,
deposits_,
Expand Down
22 changes: 11 additions & 11 deletions tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsScaled.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ contract ERC20PoolLiquidationsScaledTest is ERC20DSTestPlus {
function testSettleAuctionWithoutTakes(
uint8 collateralPrecisionDecimals_,
uint8 quotePrecisionDecimals_,
uint16 startBucketId_) external tearDown
{
uint16 startBucketId_
) external tearDown {
uint256 boundColPrecision = bound(uint256(collateralPrecisionDecimals_), 6, 18);
uint256 boundQuotePrecision = bound(uint256(quotePrecisionDecimals_), 6, 18);
uint256 startBucketId = bound(uint256(startBucketId_), 1000, 6388);
Expand All @@ -193,10 +193,10 @@ contract ERC20PoolLiquidationsScaledTest is ERC20DSTestPlus {
assertLt(_borrowerCollateralization(_borrower), 1e18);

// Kick an auction and wait for a meaningful price
assertEq(_quote.balanceOf(_bidder), 200_000 * _quoteTokenPrecision);
assertEq(_quote.balanceOf(_bidder), 300_000 * _quoteTokenPrecision);
_kick(_borrower, _bidder);
// assert bidder locked balance in auction bond
assertLt(_quote.balanceOf(_bidder), 200_000 * _quoteTokenPrecision);
assertLt(_quote.balanceOf(_bidder), 300_000 * _quoteTokenPrecision);

(uint256 auctionPrice, uint256 auctionDebt, uint256 auctionCollateral) = _advanceAuction(9 hours);
assertGt(auctionPrice, 0);
Expand Down Expand Up @@ -227,10 +227,10 @@ contract ERC20PoolLiquidationsScaledTest is ERC20DSTestPlus {
if ( bondTransferAmount * _pool.quoteTokenScale() < claimableBond ) roundingDiff = 1;

// ensure bidders can still withdraw their bonds
assertLt(_quote.balanceOf(_bidder), 200_000 * _quoteTokenPrecision);
assertLt(_quote.balanceOf(_bidder), 300_000 * _quoteTokenPrecision);
changePrank(_bidder);
_pool.withdrawBonds(_bidder, type(uint256).max);
assertEq(_quote.balanceOf(_bidder), 200_000 * _quoteTokenPrecision - roundingDiff);
assertEq(_quote.balanceOf(_bidder), 300_000 * _quoteTokenPrecision - roundingDiff);
}

function testLiquidationKickWithDeposit(
Expand Down Expand Up @@ -299,14 +299,14 @@ contract ERC20PoolLiquidationsScaledTest is ERC20DSTestPlus {
_pool.kickWithDeposit(bucketId, MAX_FENWICK_INDEX);
_checkAuctionStateUponKick(lender);

// confirm user has redeemed some of their LP to post liquidation bond
// confirm user doesn't redeemed any of their LP to post liquidation bond
(uint256 lenderLP, ) = _pool.lenderInfo(bucketId, lender);
assertLt(lenderLP, lastLenderLP);
assertEq(lenderLP, lastLenderLP);

// confirm deposit has been removed from bucket
// confirm deposit wasn't removed from bucket
(, uint256 bucketDeposit, , uint256 bucketLP, , ) = _poolUtils.bucketInfo(address(_pool), bucketId);
assertLt(bucketDeposit, lastBucketDeposit);
assertLt(bucketLP, lastBucketLP);
assertTrue(bucketDeposit >= lastBucketDeposit);
assertEq(bucketLP, lastBucketLP);
}

function _checkAuctionStateUponKick(address kicker) internal {
Expand Down

0 comments on commit 586c305

Please sign in to comment.