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

Updated auctionInfo #996

Merged
merged 4 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PoolInfoUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract PoolInfoUtils {
{
IPool pool = IPool(ajnaPool_);
uint256 referencePrice;
( , , , kickTime_, referencePrice, neutralPrice_, , , ) = pool.auctionInfo(borrower_);
( , , , kickTime_, referencePrice, neutralPrice_, , , , ) = pool.auctionInfo(borrower_);
if (kickTime_ != 0) {
(debtToCover_, collateral_, ) = this.borrowerInfo(ajnaPool_, borrower_);

Expand Down
2 changes: 2 additions & 0 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
uint256 kickTime_,
uint256 referencePrice_,
uint256 neutralPrice_,
uint256 thresholdPrice_,
address head_,
address next_,
address prev_
Expand All @@ -758,6 +759,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
liquidation.kickTime,
liquidation.referencePrice,
liquidation.neutralPrice,
liquidation.thresholdPrice,
auctions.head,
liquidation.next,
liquidation.prev
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/pool/commons/IPoolState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IPoolState {
* @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.
Expand All @@ -30,6 +31,7 @@ interface IPoolState {
uint256 kickTime_,
uint256 referencePrice_,
uint256 neutralPrice_,
uint256 thresholdPrice_,
address head_,
address next_,
address prev_
Expand Down
10 changes: 5 additions & 5 deletions tests/brownie/test_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def pool_buckets(self):
def pool_debt_in_auction(self):
auctioned_borrowers_debt = 0
for borrower in self.borrowers:
(_, _, _, kick_time, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
(_, _, _, kick_time, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
if kick_time != 0:
(borrower_debt, _, _) = self.pool.borrowerInfo(borrower)
auctioned_borrowers_debt += borrower_debt
Expand All @@ -185,7 +185,7 @@ def pool_auction_bonds(self):

auction_bonds_locked = 0
for borrower in self.borrowers:
(_, _, bond_size, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
(_, _, bond_size, _, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
auction_bonds_locked += bond_size

# Invariant 8: sum of bonds across all auctions = sum of locked balances across all kickers = total bond escrowed accumulator
Expand All @@ -202,7 +202,7 @@ def pool_loans_and_auctions(self):
if borrower_debt != 0:
borrowers_with_debt += 1

(_, _, _, kick_time, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
(_, _, _, kick_time, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrower)
if kick_time != 0:
number_of_auctions += 1

Expand Down Expand Up @@ -565,7 +565,7 @@ def rule_repay_debt(self, st_borrow_amount, st_borrower, st_sleep):
def rule_kick_auction(self, st_borrow_amount, st_lender, st_borrower, st_kicker, st_sleep):

# do not kick if already active
(_, _, _, kick_time, _, _, _, _, _, _) = self.pool.auctionInfo(borrowers[st_borrower])
(_, _, _, kick_time, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrowers[st_borrower])
if kick_time != 0:
return

Expand Down Expand Up @@ -605,7 +605,7 @@ def rule_take_auction(self, st_borrow_amount, st_take_amount, st_lender, st_borr
success = True

# kick if auction not kicked already
(_, _, _, kick_time, _, _, _, _, _, _) = self.pool.auctionInfo(borrowers[st_borrower])
(_, _, _, kick_time, _, _, _, _, _, _, _) = self.pool.auctionInfo(borrowers[st_borrower])
if kick_time == 0:
self.rule_kick_auction(st_borrow_amount, st_lender, st_borrower, st_kicker, st_sleep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract PanicExitERC20PoolHandler is UnboundedLiquidationPoolHandler, Unbounded

_actor = _borrowers[borrowerIndex_];
changePrank(_actor);
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(_actor);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(_actor);
if (block.timestamp > kickTime + 72 hours) {
numberOfCalls['BPanicExitPoolHandler.settleDebt']++;
_settleAuction(_actor, numberOfBuckets);
Expand Down Expand Up @@ -164,7 +164,7 @@ contract PanicExitERC20PoolHandler is UnboundedLiquidationPoolHandler, Unbounded
function settleHeadAuction(
uint256 skippedTime_
) external useTimestamps skipTime(skippedTime_) writeLogs {
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
_settleAuction(headAuction, 10);
_resetSettledAuction(headAuction, 0);
Expand Down Expand Up @@ -218,7 +218,7 @@ contract PanicExitERC20PoolHandler is UnboundedLiquidationPoolHandler, Unbounded
}

function _resetSettledAuction(address borrower_, uint256 borrowerIndex_) internal {
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower_);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower_);
if (kickTime == 0) {
if (borrowerIndex_ != 0) _activeBorrowers.remove(borrowerIndex_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
kickerIndex_ = constrictToRange(kickerIndex_, 0, LENDERS - 1);
address kicker = _lenders[kickerIndex_];

(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower);

// Kick auction if not already kicked
if (kickTime == 0) {
Expand All @@ -71,7 +71,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
_kickAuction(borrower);
}

(,,, kickTime,,,,,) = _pool.auctionInfo(borrower);
(,,, kickTime,,,,,,) = _pool.auctionInfo(borrower);

if (kickTime == 0) return;

Expand Down Expand Up @@ -104,7 +104,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
actorIndex_ = constrictToRange(actorIndex_, 0, LENDERS - 1);
address payer = _lenders[actorIndex_];

(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower);

// Kick auction if not already kicked
if (kickTime == 0) {
Expand All @@ -113,7 +113,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
_kickAuction(borrower);
}

(,,, kickTime,,,,,) = _pool.auctionInfo(borrower);
(,,, kickTime,,,,,,) = _pool.auctionInfo(borrower);

if (kickTime == 0) return;

Expand Down Expand Up @@ -225,7 +225,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
}
}
// **CT2**: Keep track of bucketIndex when borrower is removed from auction to check collateral added into that bucket
(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower_);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower_);
if (kickTime == 0 && collateral % 1e18 != 0 && _pool.poolType() == 1) {
buckets.add(7388);
lenderDepositTime[borrower_][7388] = block.timestamp;
Expand Down Expand Up @@ -294,7 +294,7 @@ contract SettleERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBas
}

function _resetSettledAuction(address borrower_, uint256 borrowerIndex_) internal {
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower_);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower_);
if (kickTime == 0) {
if (borrowerIndex_ != 0) _activeBorrowers.remove(borrowerIndex_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ contract TradingERC20PoolHandler is UnboundedLiquidationPoolHandler, UnboundedBa
}

function _resetSettledAuction(address borrower_, uint256 borrowerIndex_) internal {
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower_);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower_);
if (kickTime == 0) {
if (borrowerIndex_ != 0) _activeBorrowers.remove(borrowerIndex_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract PanicExitERC721PoolHandler is UnboundedLiquidationPoolHandler, Unbounde

_actor = _borrowers[borrowerIndex_];
changePrank(_actor);
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(_actor);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(_actor);
if (block.timestamp > kickTime + 72 hours) {
numberOfCalls['BPanicExitPoolHandler.settleDebt']++;
_settleAuction(_actor, numberOfBuckets);
Expand Down Expand Up @@ -162,7 +162,7 @@ contract PanicExitERC721PoolHandler is UnboundedLiquidationPoolHandler, Unbounde
function settleHeadAuction(
uint256 skippedTime_
) external useTimestamps skipTime(skippedTime_) writeLogs {
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
_settleAuction(headAuction, 10);
_resetSettledAuction(headAuction, 0);
Expand Down Expand Up @@ -216,7 +216,7 @@ contract PanicExitERC721PoolHandler is UnboundedLiquidationPoolHandler, Unbounde
}

function _resetSettledAuction(address borrower_, uint256 borrowerIndex_) internal {
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower_);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower_);
if (kickTime == 0) {
if (borrowerIndex_ != 0) _activeBorrowers.remove(borrowerIndex_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ contract BucketBankruptcyERC20PoolRewardsHandler is UnboundedBasicERC20PoolHandl
) external useTimestamps useRandomActor(takerIndex_) skipTime(skippedTime_) writeLogs {
address borrower = _borrowers[constrictToRange(borrowerIndex_, 0, _borrowers.length - 1)];

(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);

// Kick borrower if not already kicked
if (kickTime == 0) {
Expand Down Expand Up @@ -255,7 +255,7 @@ contract BucketBankruptcyERC20PoolRewardsHandler is UnboundedBasicERC20PoolHandl
/*******************************/

function _resetSettledAuction(address borrower_, uint256 borrowerIndex_) internal {
(,,, uint256 kickTime,,,,,) = _pool.auctionInfo(borrower_);
(,,, uint256 kickTime,,,,,,) = _pool.auctionInfo(borrower_);
if (kickTime == 0) {
if (borrowerIndex_ != 0) _activeBorrowers.remove(borrowerIndex_);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/forge/invariants/base/BasicInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ abstract contract BasicInvariants is BaseInvariants {
for (uint256 i = 0; i < actorCount; i++) {
address borrower = IBaseHandler(_handler).actors(i);

(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);

if (kickTime == 0) {
(uint256 borrowerT0Debt, uint256 borrowerCollateral, ) = _pool.borrowerInfo(borrower);
Expand Down
8 changes: 4 additions & 4 deletions tests/forge/invariants/base/LiquidationInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract contract LiquidationInvariants is BasicInvariants {

for (uint256 i = 0; i < actorCount; i++) {
address borrower = IBaseHandler(_handler).actors(i);
(, , , uint256 kickTime, , , , ,) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);

if (kickTime != 0) {
(uint256 t0debt, , ) = _pool.borrowerInfo(borrower);
Expand Down Expand Up @@ -62,7 +62,7 @@ abstract contract LiquidationInvariants is BasicInvariants {
uint256 lockedBonds;
for (uint256 i = 0; i < actorCount; i++) {
address borrower = IBaseHandler(_handler).actors(i);
(, , uint256 bond, , , , , , ) = _pool.auctionInfo(borrower);
(, , uint256 bond, , , , , , , ) = _pool.auctionInfo(borrower);
lockedBonds += bond;
}
require(lockedBonds == kickerLockedBond, "A2: bonds in auctions != than kicker locked bonds");
Expand Down Expand Up @@ -94,7 +94,7 @@ abstract contract LiquidationInvariants is BasicInvariants {
for (uint256 i = 0; i < actorCount; i++) {
address borrower = IBaseHandler(_handler).actors(i);

(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);

if (kickTime != 0) borrowersKicked += 1;
}
Expand All @@ -108,7 +108,7 @@ abstract contract LiquidationInvariants is BasicInvariants {

for (uint256 i = 0; i < actorCount; i++) {
address borrower = IBaseHandler(_handler).actors(i);
(address kicker, , uint256 bondSize, , , , , , ) = _pool.auctionInfo(borrower);
(address kicker, , uint256 bondSize, , , , , , , ) = _pool.auctionInfo(borrower);
(, uint256 lockedAmount) = _pool.kickerInfo(kicker);

require(lockedAmount >= bondSize, "Auction Invariant A5");
Expand Down
12 changes: 6 additions & 6 deletions tests/forge/invariants/base/handlers/LiquidationPoolHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ abstract contract LiquidationPoolHandler is UnboundedLiquidationPoolHandler, Bas

address borrower;
// try to take from head auction if any
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
(, uint256 auctionedCollateral, ) = _poolInfo.borrowerInfo(address(_pool), headAuction);
borrower = headAuction;
amount_ = auctionedCollateral / 2;

(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);
// skip to make auction takeable
if (block.timestamp - kickTime < 1 hours) {
vm.warp(block.timestamp + 61 minutes);
Expand Down Expand Up @@ -91,11 +91,11 @@ abstract contract LiquidationPoolHandler is UnboundedLiquidationPoolHandler, Bas

address borrower;
// try to take from head auction if any
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
borrower = headAuction;

(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower);
// skip to make auction takeable
if (block.timestamp - kickTime < 1 hours) {
vm.warp(block.timestamp + 61 minutes);
Expand Down Expand Up @@ -126,7 +126,7 @@ abstract contract LiquidationPoolHandler is UnboundedLiquidationPoolHandler, Bas

address borrower;
// try to settle head auction if any
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
borrower = headAuction;
} else {
Expand All @@ -150,7 +150,7 @@ abstract contract LiquidationPoolHandler is UnboundedLiquidationPoolHandler, Bas
borrower_ = actors[borrowerIndex_];
amount_ = constrictToRange(amount_, MIN_QUOTE_AMOUNT, MAX_QUOTE_AMOUNT);

( , , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower_);
( , , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower_);

borrowerKicked_ = kickTime != 0;

Expand Down
10 changes: 5 additions & 5 deletions tests/forge/invariants/base/handlers/unbounded/BaseHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ abstract contract BaseHandler is Test {
address currentActor = _actor;

// clear head auction if more than 72 hours passed
(, , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
(, , , , , , , address headAuction, , ) = _pool.auctionInfo(address(0));
if (headAuction != address(0)) {
(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(headAuction);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(headAuction);
if (block.timestamp - kickTime > 72 hours) {
(uint256 auctionedDebt, , ) = _poolInfo.borrowerInfo(address(_pool), headAuction);

Expand Down Expand Up @@ -491,7 +491,7 @@ abstract contract BaseHandler is Test {
) = _poolInfo.poolLoansInfo(address(_pool));

(
, , , , , ,
, , , , , , ,
address headAuction, ,
) = _pool.auctionInfo(address(0));

Expand Down Expand Up @@ -599,11 +599,11 @@ abstract contract BaseHandler is Test {
uint256 bondFactor;
uint256 bondSize;
uint256 neutralPrice;
(,,,,,, nextBorrower,,) = _pool.auctionInfo(address(0));
(,,,,,,, nextBorrower,,) = _pool.auctionInfo(address(0));
while (nextBorrower != address(0)) {
data = string(abi.encodePacked("Borrower ", Strings.toHexString(uint160(nextBorrower), 20), " Auction Details :"));
printInNextLine(data);
(, bondFactor, bondSize, kickTime, referencePrice, neutralPrice,, nextBorrower,) = _pool.auctionInfo(nextBorrower);
(, bondFactor, bondSize, kickTime, referencePrice, neutralPrice,,, nextBorrower,) = _pool.auctionInfo(nextBorrower);

printLog("Bond Factor = ", bondFactor);
printLog("Bond Size = ", bondSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ abstract contract UnboundedLiquidationPoolHandler is BaseHandler {
) internal updateLocalStateAndPoolInterest {
numberOfCalls['UBLiquidationHandler.takeAuction']++;

(address kicker, , , , , , , , ) = _pool.auctionInfo(borrower_);
(address kicker, , , , , , , , , ) = _pool.auctionInfo(borrower_);

(
uint256 borrowerDebtBeforeTake,
Expand Down Expand Up @@ -198,7 +198,7 @@ abstract contract UnboundedLiquidationPoolHandler is BaseHandler {
) internal updateLocalStateAndPoolInterest {
numberOfCalls['UBLiquidationHandler.bucketTake']++;

(address kicker, , , , , , , , ) = _pool.auctionInfo(borrower_);
(address kicker, , , , , , , , , ) = _pool.auctionInfo(borrower_);
( , , , , uint256 auctionPrice, ) = _poolInfo.auctionStatus(address(_pool), borrower_);
uint256 auctionBucketIndex = auctionPrice < MIN_PRICE ? 7388 : (auctionPrice > MAX_PRICE ? 0 : _indexOf(auctionPrice));

Expand Down Expand Up @@ -266,7 +266,7 @@ abstract contract UnboundedLiquidationPoolHandler is BaseHandler {
exchangeRateShouldNotChange[bucketIndex_] = true;

// **CT2**: Keep track of bucketIndex when borrower is removed from auction to check collateral added into that bucket
(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower_);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower_);
if (kickTime == 0 && _pool.poolType() == 1) {
buckets.add(auctionBucketIndex);
if (beforeBucketTakeVars.borrowerLps < afterBucketTakeVars.borrowerLps) {
Expand Down Expand Up @@ -380,7 +380,7 @@ abstract contract UnboundedLiquidationPoolHandler is BaseHandler {
}
}
// **CT2**: Keep track of bucketIndex when borrower is removed from auction to check collateral added into that bucket
(, , , uint256 kickTime, , , , , ) = _pool.auctionInfo(borrower_);
(, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower_);
if (kickTime == 0 && collateral % 1e18 != 0 && _pool.poolType() == 1) {
buckets.add(7388);
lenderDepositTime[borrower_][7388] = block.timestamp;
Expand Down
Loading
Loading