Skip to content

Commit

Permalink
Sherlock 92: startClaimableReserveAuction using old inflator (#587)
Browse files Browse the repository at this point in the history
* Sherlock 92: startClaimableReserveAuction using old inflator

* Add test to show interest accrued when start reserve auction
  • Loading branch information
grandizzy authored Feb 11, 2023
1 parent d45aec9 commit 1414435
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,16 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
revert ReserveAuctionTooSoon();
}

PoolState memory poolState = _accruePoolInterest();

// start a new claimable reserve auction, passing in relevant parameters such as the current pool size, debt, balance, and inflator value
uint256 kickerAward = Auctions.startClaimableReserveAuction(
auctions,
reserveAuction,
StartReserveAuctionParams({
poolSize: Deposits.treeSum(deposits),
t0PoolDebt: poolBalances.t0Debt,
poolBalance: _getNormalizedPoolQuoteTokenBalance(),
inflator: inflatorState.inflator
poolDebt: poolState.debt,
poolSize: Deposits.treeSum(deposits)
})
);

Expand All @@ -368,6 +369,9 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
reserveAuction.latestBurnEventEpoch = latestBurnEpoch;
reserveAuction.burnEvents[latestBurnEpoch].timestamp = block.timestamp;

// update pool interest rate state
_updateInterestState(poolState, _lup(poolState.debt));

// transfer kicker award to msg.sender
_transferQuoteToken(msg.sender, kickerAward);
}
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/pool/commons/IPoolReserveAuctionActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ interface IPoolReserveAuctionActions {
/*********************/

struct StartReserveAuctionParams {
uint256 poolSize; // [WAD] total deposits in pool (with accrued debt)
uint256 t0PoolDebt; // [WAD] current t0 pool debt
uint256 poolBalance; // [WAD] pool quote token balance
uint256 inflator; // [WAD] pool current inflator
uint256 poolDebt; // [WAD] current pool debt
uint256 poolSize; // [WAD] total deposits in pool (with accrued debt)
}
2 changes: 1 addition & 1 deletion src/libraries/external/Auctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ library Auctions {
uint256 curUnclaimedAuctionReserve = reserveAuction_.unclaimed;

uint256 claimable = _claimableReserves(
Maths.wmul(params_.t0PoolDebt, params_.inflator),
params_.poolDebt,
params_.poolSize,
auctions_.totalBondEscrowed,
curUnclaimedAuctionReserve,
Expand Down
50 changes: 50 additions & 0 deletions tests/forge/ERC20Pool/ERC20PoolReserveAuction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract {
ERC20 AJNA = ERC20(_ajna);

address internal _borrower;
address internal _borrower2;
address internal _lender;
address internal _bidder;

function setUp() external {
_pool = ERC20Pool(new ERC20PoolFactory(address(AJNA)).deployPool(address(WBTC), address(USDC), 0.05 * 10**18));

_borrower = makeAddr("borrower");
_borrower2 = makeAddr("borrower2");
_lender = makeAddr("lender");
_bidder = makeAddr("bidder");

deal(address(WBTC), _borrower, 10 * 1e8);
deal(address(WBTC), _borrower2, 10 * 1e8);
deal(address(USDC), _borrower, 100 * 1e6);

deal(address(USDC), _lender, 10_000 * 1e6);
Expand All @@ -40,6 +43,9 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract {
WBTC.approve(address(_pool), 10 * 1e18);
USDC.approve(address(_pool), 1_000 * 1e18);

changePrank(_borrower2);
WBTC.approve(address(_pool), 10 * 1e18);

changePrank(_bidder);
AJNA.approve(address(_pool), 10 * 1e18);

Expand Down Expand Up @@ -112,4 +118,48 @@ contract ERC20PoolReserveAuctionTest is ERC20HelperContract {
assertEq(USDC.balanceOf(address(_bidder)), 1.297968 * 1e6);
assertEq(AJNA.balanceOf(address(_bidder)), 9.999999998885449254 * 1e18);
}

function testReserveAuctionAccrueInterest() external {
_drawDebtNoLupCheck({
from: _borrower2,
borrower: _borrower2,
amountToBorrow: 300 * 1e18,
limitIndex: 7000,
collateralToPledge: 1 * 1e18
});

skip(26 weeks);

// repay entire debt
_repayDebtNoLupCheck({
from: _borrower,
borrower: _borrower,
amountToRepay: 400 * 1e18,
amountRepaid: 307.869212479869665749 * 1e18,
collateralToPull: 0
});

uint256 reservesWithoutNewInterest = 0.705309714116053616 * 1e18;
uint256 reservesWithNewInterest = 1.789580885547436858 * 1e18;

uint256 snapshot = vm.snapshot();

// kick off a new auction without new interest accrued
_startClaimableReserveAuction({
from: _bidder,
remainingReserves: reservesWithoutNewInterest,
price: 1000000000 * 1e18
});

vm.revertTo(snapshot);

skip(26 weeks);

// kick off a new auction with 26 weeks interest accrued
_startClaimableReserveAuction({
from: _bidder,
remainingReserves: reservesWithNewInterest,
price: 1000000000 * 1e18
});
}
}

0 comments on commit 1414435

Please sign in to comment.