Skip to content

Commit

Permalink
feat: add ability to pause auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed May 30, 2023
1 parent 7cf9407 commit c12a6da
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
40 changes: 40 additions & 0 deletions contracts/Shortfall/Shortfall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
/// @notice Time to wait for next bidder. initially waits for 10 blocks
uint256 public nextBidderBlockLimit;

/// @notice Boolean of if auctions are paused
bool public auctionsPaused;

/// @notice Time to wait for first bidder. initially waits for 100 blocks
uint256 public waitForFirstBidder;

Expand Down Expand Up @@ -123,6 +126,12 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
/// @notice Emitted when incentiveBps is updated
event IncentiveBpsUpdated(uint256 oldIncentiveBps, uint256 newIncentiveBps);

/// @notice Emitted when auctions are paused
event AuctionsPaused(address sender);

/// @notice Emitted when auctions are unpaused
event AuctionsResumed(address sender);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
// Note that the contract is upgradeable. Use initialize() or reinitializers
Expand Down Expand Up @@ -158,6 +167,7 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
waitForFirstBidder = DEFAULT_WAIT_FOR_FIRST_BIDDER;
nextBidderBlockLimit = DEFAULT_NEXT_BIDDER_BLOCK_LIMIT;
incentiveBps = DEFAULT_INCENTIVE_BPS;
auctionsPaused = false;
}

/**
Expand Down Expand Up @@ -216,6 +226,7 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
* @notice Close an auction
* @param comptroller Comptroller address of the pool
* @custom:event Emits AuctionClosed event on successful close
* @custom:event Errors if auctions are paused
*/
function closeAuction(address comptroller) external nonReentrant {
Auction storage auction = auctions[comptroller];
Expand Down Expand Up @@ -273,15 +284,18 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
* @notice Start a auction when there is not currently one active
* @param comptroller Comptroller address of the pool
* @custom:event Emits AuctionStarted event on success
* @custom:event Errors if auctions are paused
*/
function startAuction(address comptroller) external {
require(!auctionsPaused, "Auctions are paused");
_startAuction(comptroller);
}

/**
* @notice Restart an auction
* @param comptroller Address of the pool
* @custom:event Emits AuctionRestarted event on successful restart
* @custom:event Errors if auctions are paused
*/
function restartAuction(address comptroller) external {
Auction storage auction = auctions[comptroller];
Expand Down Expand Up @@ -364,6 +378,32 @@ contract Shortfall is Ownable2StepUpgradeable, AccessControlledV8, ReentrancyGua
emit PoolRegistryUpdated(oldPoolRegistry, poolRegistry_);
}

/**
* @notice Pause auctions. This disables starting new auctions but lets the current auction finishes
* @custom:event Emits AuctionsPaused on success
* @custom:error Errors is auctions are paused
* @custom:access Restricted by ACM
*/
function pauseAuctions() external {
_checkAccessAllowed("pauseAuctions()");
require(!auctionsPaused, "Auctions are already paused");
auctionsPaused = true;
emit AuctionsPaused(msg.sender);
}

/**
* @notice Resume paused auctions.
* @custom:event Emits AuctionsResumed on success
* @custom:error Errors is auctions are active
* @custom:access Restricted by ACM
*/
function resumeAuctions() external {
_checkAccessAllowed("resumeAuctions()");
require(auctionsPaused, "Auctions are not paused");
auctionsPaused = false;
emit AuctionsResumed(msg.sender);
}

/**
* @notice Start a auction when there is not currently one active
* @param comptroller Comptroller address of the pool
Expand Down
35 changes: 35 additions & 0 deletions tests/hardhat/Shortfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ async function shortfallFixture() {

await accessControlManager.giveCallPermission(shortfall.address, "updateWaitForFirstBidder(uint256)", owner.address);

await accessControlManager.giveCallPermission(shortfall.address, "pauseAuctions()", owner.address);

await accessControlManager.giveCallPermission(
shortfall.address,
"updateNextBidderBlockLimit(uint256)",
Expand Down Expand Up @@ -607,13 +609,46 @@ describe("Shortfall: Tests", async function () {
await mockDAI.approve(shortfall.address, parseUnits("50000", 18));
await mockWBTC.approve(shortfall.address, parseUnits("50000", 8));

// simulate transferReserveForAuction
await mockBUSD.transfer(shortfall.address, auction.seizedRiskFund);

await shortfall.placeBid(poolAddress, auction.startBidBps);

await mine(100);

await expect(shortfall.restartAuction(poolAddress)).to.be.revertedWith(
"you need to wait for more time for first bidder",
);
// Close out auction created for this test case
await mine(10);
await shortfall.closeAuction(poolAddress);
});
});

describe("Auctions can be enabled and disabled", async function () {
it("fails if called by a non permissioned account", async function () {
await expect(shortfall.connect(someone).pauseAuctions()).to.be.reverted;
});

it("can close current auction but not start new one when they are paused", async function () {
vDAI.badDebt.returns(parseUnits("10000", 18));
await vDAI.setVariable("badDebt", parseUnits("10000", 18));
vWBTC.badDebt.returns(parseUnits("2", 8));
await vWBTC.setVariable("badDebt", parseUnits("2", 8));

await shortfall.startAuction(poolAddress);
const auction = await shortfall.auctions(poolAddress);

await expect(shortfall.connect(owner).pauseAuctions())
.to.emit(shortfall, "AuctionsPaused")
.withArgs(owner.address);

await shortfall.placeBid(poolAddress, auction.startBidBps);
// Close out auction created for this test case
await mine(10);
await expect(shortfall.closeAuction(poolAddress));

await expect(shortfall.startAuction(poolAddress)).to.be.revertedWith("Auctions are paused");
});
});
});

0 comments on commit c12a6da

Please sign in to comment.