diff --git a/src/PoolInfoUtils.sol b/src/PoolInfoUtils.sol index 4d69fa22c..bf823f43f 100644 --- a/src/PoolInfoUtils.sol +++ b/src/PoolInfoUtils.sol @@ -313,7 +313,7 @@ contract PoolInfoUtils { uint256 quoteTokenBalance = IERC20Token(pool.quoteTokenAddress()).balanceOf(ajnaPool_) * pool.quoteTokenScale(); - (uint256 bondEscrowed, uint256 unclaimedReserve, uint256 lastKickedReserves, uint256 auctionKickTime, ) = pool.reservesInfo(); + (uint256 bondEscrowed, uint256 unclaimedReserve, uint256 auctionKickTime, uint256 lastKickedReserves, ) = pool.reservesInfo(); // due to rounding issues, especially in Auction.settle, this can be slighly negative if (poolDebt + quoteTokenBalance >= poolSize + bondEscrowed + unclaimedReserve) { diff --git a/src/libraries/helpers/PoolHelper.sol b/src/libraries/helpers/PoolHelper.sol index b2b09e609..60c802990 100644 --- a/src/libraries/helpers/PoolHelper.sol +++ b/src/libraries/helpers/PoolHelper.sol @@ -393,7 +393,7 @@ import { Maths } from '../internal/Maths.sol'; uint256 secondsElapsed = block.timestamp - reserveAuctionKicked_; uint256 hoursComponent = 1e27 >> secondsElapsed / 3600; uint256 minutesComponent = Maths.rpow(MINUTE_HALF_LIFE, secondsElapsed % 3600 / 60); - uint256 initialPrice = Maths.wdiv(1_000_000_000 * 1e18, lastKickedReserves_); + uint256 initialPrice = lastKickedReserves_ == 0 ? 0 : Maths.wdiv(1_000_000_000 * 1e18, lastKickedReserves_); // TODO: clean up rounding by implementing appropriate Math library method price_ = initialPrice * Maths.rmul(hoursComponent, minutesComponent) / 1e27; diff --git a/tests/forge/unit/Auctions.t.sol b/tests/forge/unit/Auctions.t.sol index 24f831f4c..4237ad302 100644 --- a/tests/forge/unit/Auctions.t.sol +++ b/tests/forge/unit/Auctions.t.sol @@ -103,6 +103,9 @@ contract AuctionsTest is DSTestPlus { assertEq(_reserveAuctionPrice(block.timestamp - 16 hours, lastKickedReserves), 0.000005086263020833 * 1e18); assertEq(_reserveAuctionPrice(block.timestamp - 32 hours, lastKickedReserves), 0.000000000077610214 * 1e18); assertEq(_reserveAuctionPrice(block.timestamp - 64 hours, lastKickedReserves), 0); + + // ensure it handles zeros properly + assertEq(_reserveAuctionPrice(0, 0), 0); } /** diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolReserveAuction.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolReserveAuction.t.sol index a93f7293e..431b4f0f9 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolReserveAuction.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolReserveAuction.t.sol @@ -61,7 +61,7 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract { }); } - function testStartAndTakeUsdcReserveAuction() external { + function testStartAndTakeUsdcReserveAuction() external tearDown { // skip time to accumulate interest skip(26 weeks); @@ -89,7 +89,7 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract { _kickReserveAuction({ from: _bidder, remainingReserves: 1.471235793861737556 * 1e18, - price: 1000000000 * 1e18, + price: 679_700_700.711729067726118823 * 1e18, epoch: 1 }); @@ -99,7 +99,7 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract { reserves: 0.000001006397976200 * 1e18, claimableReserves : 0, claimableReservesRemaining: 1.471235793861737556 * 1e18, - auctionPrice: 0.000000000867361737 * 1e18, + auctionPrice: 0.000000000589546380 * 1e18, timeRemaining: 43200 }); @@ -113,7 +113,7 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract { _pool.takeReserves(10 * 1e18); assertEq(USDC.balanceOf(address(_pool)), 1_006.397978 * 1e6); assertEq(USDC.balanceOf(address(_bidder)), 1.471235 * 1e6); - assertEq(AJNA.balanceOf(address(_bidder)), 9.999999998723906366 * 1e18); + assertEq(AJNA.balanceOf(address(_bidder)), 9.999999999132638263 * 1e18); } function testZeroBid() external {