diff --git a/brownie-config.yml b/brownie-config.yml index 9171503eb..6ecf393ea 100644 --- a/brownie-config.yml +++ b/brownie-config.yml @@ -17,7 +17,7 @@ compiler: version: 0.8.14 optimizer: enabled: true - runs: 100 + runs: 500 remappings: - "@ds-math=lib/ds-math/src/" - "@openzeppelin/contracts=lib/openzeppelin-contracts/contracts" diff --git a/foundry.toml b/foundry.toml index 9b89e209c..cd08fd34e 100644 --- a/foundry.toml +++ b/foundry.toml @@ -18,7 +18,7 @@ block_number = 16_295_000 fork_block_number = 16_295_000 rpc_storage_caching = { chains = ["mainnet"], endpoints = "all" } optimizer = true -optimizer_runs = 100 +optimizer_runs = 500 [fuzz] runs = 300 diff --git a/src/ERC20Pool.sol b/src/ERC20Pool.sol index 02c397431..1c6be5934 100644 --- a/src/ERC20Pool.sol +++ b/src/ERC20Pool.sol @@ -26,7 +26,6 @@ import { import { DrawDebtResult, - BucketTakeResult, RepayDebtResult, SettleParams, SettleResult, @@ -125,6 +124,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - increment `poolBalances.pledgedCollateral` accumulator * @dev - increment `poolBalances.t0Debt` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if loan not in auction, debt and collateral pre action are considered 0 if auction settled * @dev === Emit events === * @dev - `DrawDebt` */ @@ -153,26 +153,31 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { emit DrawDebt(borrowerAddress_, amountToBorrow_, collateralToPledge_, result.newLup); - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state + // update in memory pool state struct poolState.debt = result.poolDebt; poolState.t0Debt = result.t0PoolDebt; + if (result.t0DebtInAuctionChange != 0) poolState.t0DebtInAuction -= result.t0DebtInAuctionChange; poolState.collateral = result.poolCollateral; + + // adjust t0Debt2ToCollateral ratio if loan not in auction + if (!result.inAuction) { + _updateT0Debt2ToCollateral( + result.settledAuction ? 0 : result.debtPreAction, // debt pre settle (for loan in auction) not taken into account + result.debtPostAction, + result.settledAuction ? 0 : result.collateralPreAction, // collateral pre settle (for loan in auction) not taken into account + result.collateralPostAction + ); + } + + // update pool interest rate state _updateInterestState(poolState, result.newLup); if (collateralToPledge_ != 0) { // update pool balances state if (result.t0DebtInAuctionChange != 0) { - poolBalances.t0DebtInAuction -= result.t0DebtInAuctionChange; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; } - poolBalances.pledgedCollateral += collateralToPledge_; + poolBalances.pledgedCollateral = poolState.collateral; // move collateral from sender to pool _transferCollateralFrom(msg.sender, collateralToPledge_); @@ -180,7 +185,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { if (amountToBorrow_ != 0) { // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; + poolBalances.t0Debt = poolState.t0Debt; // move borrowed amount from pool to sender _transferQuoteToken(msg.sender, amountToBorrow_); @@ -193,6 +198,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { * @dev - decrement `poolBalances.t0Debt accumulator` * @dev - decrement `poolBalances.t0DebtInAuction accumulator` * @dev - decrement `poolBalances.pledgedCollateral accumulator` + * @dev - update `t0Debt2ToCollateral` ratio only if loan not in auction, debt and collateral pre action are considered 0 if auction settled * @dev === Emit events === * @dev - `RepayDebt` */ @@ -223,25 +229,30 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { emit RepayDebt(borrowerAddress_, result.quoteTokenToRepay, collateralAmountToPull_, result.newLup); - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state + // update in memory pool state struct poolState.debt = result.poolDebt; poolState.t0Debt = result.t0PoolDebt; + if (result.t0DebtInAuctionChange != 0) poolState.t0DebtInAuction -= result.t0DebtInAuctionChange; poolState.collateral = result.poolCollateral; + + // adjust t0Debt2ToCollateral ratio if loan not in auction + if (!result.inAuction) { + _updateT0Debt2ToCollateral( + result.settledAuction ? 0 : result.debtPreAction, // debt pre settle (for loan in auction) not taken into account + result.debtPostAction, + result.settledAuction ? 0 : result.collateralPreAction, // collateral pre settle (for loan in auction) not taken into account + result.collateralPostAction + ); + } + + // update pool interest rate state _updateInterestState(poolState, result.newLup); if (result.quoteTokenToRepay != 0) { // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; + poolBalances.t0Debt = poolState.t0Debt; if (result.t0DebtInAuctionChange != 0) { - poolBalances.t0DebtInAuction -= result.t0DebtInAuctionChange; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; } // move amount to repay from sender to pool @@ -249,7 +260,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { } if (collateralAmountToPull_ != 0) { // update pool balances state - poolBalances.pledgedCollateral = result.poolCollateral; + poolBalances.pledgedCollateral = poolState.collateral; // move collateral from pool to address specified as collateral receiver _transferCollateral(collateralReceiver_, collateralAmountToPull_); @@ -337,6 +348,8 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - no update of `t0Debt2ToCollateral` ratio as debt and collateral pre settle are not taken into account (pre debt and pre collateral = 0) + * @dev and loan is removed from auction queue only when there's no more debt (post debt = 0) */ function settle( address borrowerAddress_, @@ -358,24 +371,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { }) ); - // update pool balances state - poolBalances.t0Debt -= result.t0DebtSettled; - poolBalances.t0DebtInAuction -= result.t0DebtSettled; - poolBalances.pledgedCollateral -= result.collateralSettled; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralRemaining - ); - - // update pool interest rate state - poolState.debt -= Maths.wmul(result.t0DebtSettled, poolState.inflator); - poolState.t0Debt -= result.t0DebtSettled; - poolState.collateral -= result.collateralSettled; - _updateInterestState(poolState, Deposits.getLup(deposits, poolState.debt)); + _updatePostSettleState(result, poolState); } /** @@ -384,6 +380,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if auction settled, debt and collateral pre action are considered 0 */ function take( address borrowerAddress_, @@ -411,28 +408,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { // round quote token up to cover the cost of purchasing the collateral result.quoteTokenAmount = _roundUpToScale(result.quoteTokenAmount, _getArgUint256(QUOTE_SCALE)); - // update pool balances state - uint256 t0DebtInAuction = poolBalances.t0DebtInAuction; - t0DebtInAuction += result.t0DebtPenalty; - t0DebtInAuction -= result.t0DebtInAuctionChange; - - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction = t0DebtInAuction; - poolBalances.pledgedCollateral -= result.collateralAmount; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state - poolState.debt = result.poolDebt; - poolState.t0Debt = result.t0PoolDebt; - poolState.collateral -= result.collateralAmount; - _updateInterestState(poolState, result.newLup); + _updatePostTakeState(result, poolState); _transferCollateral(callee_, result.collateralAmount); @@ -453,6 +429,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if auction settled, debt and collateral pre action are considered 0 */ function bucketTake( address borrowerAddress_, @@ -462,7 +439,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { PoolState memory poolState = _accruePoolInterest(); - BucketTakeResult memory result = TakerActions.bucketTake( + TakeResult memory result = TakerActions.bucketTake( auctions, buckets, deposits, @@ -474,28 +451,7 @@ contract ERC20Pool is FlashloanablePool, IERC20Pool { _bucketCollateralDust(0) ); - // update pool balances state - uint256 t0DebtInAuction = poolBalances.t0DebtInAuction; - t0DebtInAuction += result.t0DebtPenalty; - t0DebtInAuction -= result.t0DebtInAuctionChange; - - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction = t0DebtInAuction; - poolBalances.pledgedCollateral -= result.collateralAmount; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state - poolState.debt = result.poolDebt; - poolState.t0Debt = result.t0PoolDebt; - poolState.collateral -= result.collateralAmount; - _updateInterestState(poolState, result.newLup); + _updatePostTakeState(result, poolState); } /***************************/ diff --git a/src/ERC721Pool.sol b/src/ERC721Pool.sol index 1f5b2264d..74579354d 100644 --- a/src/ERC721Pool.sol +++ b/src/ERC721Pool.sol @@ -11,7 +11,6 @@ import { IPoolSettlerActions } from './interfaces/pool/IPool.sol'; import { - BucketTakeResult, DrawDebtResult, RepayDebtResult, SettleParams, @@ -132,6 +131,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - increment `poolBalances.pledgedCollateral` accumulator * @dev - increment `poolBalances.t0Debt` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if loan not in auction, debt and collateral pre action are considered 0 if auction settled * @dev - update `borrowerTokenIds` and `bucketTokenIds` arrays * @dev === Emit events === * @dev - `DrawDebtNFT` @@ -158,26 +158,31 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { emit DrawDebtNFT(borrowerAddress_, amountToBorrow_, tokenIdsToPledge_, result.newLup); - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state + // update in memory pool state struct poolState.debt = result.poolDebt; poolState.t0Debt = result.t0PoolDebt; + if (result.t0DebtInAuctionChange != 0) poolState.t0DebtInAuction -= result.t0DebtInAuctionChange; poolState.collateral = result.poolCollateral; + + // adjust t0Debt2ToCollateral ratio if loan not in auction + if (!result.inAuction) { + _updateT0Debt2ToCollateral( + result.settledAuction ? 0 : result.debtPreAction, // debt pre settle (for loan in auction) not taken into account + result.debtPostAction, + result.settledAuction ? 0 : result.collateralPreAction, // collateral pre settle (for loan in auction) not taken into account + result.collateralPostAction + ); + } + + // update pool interest rate state _updateInterestState(poolState, result.newLup); if (tokenIdsToPledge_.length != 0) { // update pool balances state if (result.t0DebtInAuctionChange != 0) { - poolBalances.t0DebtInAuction -= result.t0DebtInAuctionChange; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; } - poolBalances.pledgedCollateral = result.poolCollateral; + poolBalances.pledgedCollateral = poolState.collateral; // move collateral from sender to pool _transferFromSenderToPool(borrowerTokenIds[borrowerAddress_], tokenIdsToPledge_); @@ -188,7 +193,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { // move borrowed amount from pool to sender if (amountToBorrow_ != 0) { // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; + poolBalances.t0Debt = poolState.t0Debt; // move borrowed amount from pool to sender _transferQuoteToken(msg.sender, amountToBorrow_); @@ -201,6 +206,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { * @dev - decrement `poolBalances.t0Debt accumulator` * @dev - decrement `poolBalances.t0DebtInAuction accumulator` * @dev - decrement `poolBalances.pledgedCollateral accumulator` + * @dev - update `t0Debt2ToCollateral` ratio only if loan not in auction, debt and collateral pre action are considered 0 if auction settled * @dev - update `borrowerTokenIds` and `bucketTokenIds` arrays * @dev === Emit events === * @dev - `RepayDebt` @@ -228,30 +234,35 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { emit RepayDebt(borrowerAddress_, result.quoteTokenToRepay, noOfNFTsToPull_, result.newLup); + // update in memory pool state struct + poolState.debt = result.poolDebt; + poolState.t0Debt = result.t0PoolDebt; + if (result.t0DebtInAuctionChange != 0) poolState.t0DebtInAuction -= result.t0DebtInAuctionChange; + poolState.collateral = result.poolCollateral; + if (result.settledAuction) _rebalanceTokens(borrowerAddress_, result.remainingCollateral); - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); + // adjust t0Debt2ToCollateral ratio if loan not in auction + if (!result.inAuction) { + _updateT0Debt2ToCollateral( + result.settledAuction ? 0 : result.debtPreAction, // debt pre settle (for loan in auction) not taken into account + result.debtPostAction, + result.settledAuction ? 0 : result.collateralPreAction, // collateral pre settle (for loan in auction) not taken into account + result.collateralPostAction + ); + } // update pool interest rate state - poolState.debt = result.poolDebt; - poolState.t0Debt = result.t0PoolDebt; - poolState.collateral = result.poolCollateral; _updateInterestState(poolState, result.newLup); // update pool balances state - poolBalances.pledgedCollateral = result.poolCollateral; + poolBalances.pledgedCollateral = poolState.collateral; if (result.quoteTokenToRepay != 0) { // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; + poolBalances.t0Debt = poolState.t0Debt; if (result.t0DebtInAuctionChange != 0) { - poolBalances.t0DebtInAuction -= result.t0DebtInAuctionChange; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; } // move amount to repay from sender to pool @@ -380,6 +391,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - no update of `t0Debt2ToCollateral` ratio as debt and collateral pre settle are not taken into account (pre debt and pre collateral = 0) */ function settle( address borrowerAddress_, @@ -403,27 +415,10 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { params ); + _updatePostSettleState(result, poolState); + // move token ids from borrower array to pool claimable array if any collateral used to settle bad debt if (result.collateralSettled != 0) _rebalanceTokens(params.borrower, result.collateralRemaining); - - // update pool balances state - poolBalances.t0Debt -= result.t0DebtSettled; - poolBalances.t0DebtInAuction -= result.t0DebtSettled; - poolBalances.pledgedCollateral -= result.collateralSettled; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralRemaining - ); - - // update pool interest rate state - poolState.debt -= Maths.wmul(result.t0DebtSettled, poolState.inflator); - poolState.t0Debt -= result.t0DebtSettled; - poolState.collateral -= result.collateralSettled; - _updateInterestState(poolState, Deposits.getLup(deposits, poolState.debt)); } /** @@ -432,6 +427,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if auction settled, debt and collateral pre action are considered 0 */ function take( address borrowerAddress_, @@ -452,31 +448,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { 1 ); - // update pool balances state - uint256 t0DebtInAuction = poolBalances.t0DebtInAuction; - t0DebtInAuction += result.t0DebtPenalty; - t0DebtInAuction -= result.t0DebtInAuctionChange; - - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction = t0DebtInAuction; - - // the total collateral taken from borrower pledged collateral (collateral taken plus collateral compensated if auction settled) - uint256 collateralSettled = result.collateralAmount + result.compensatedCollateral; - poolBalances.pledgedCollateral -= collateralSettled; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state - poolState.debt = result.poolDebt; - poolState.t0Debt = result.t0PoolDebt; - poolState.collateral -= collateralSettled; - _updateInterestState(poolState, result.newLup); + _updatePostTakeState(result, poolState); // transfer rounded collateral from pool to taker uint256[] memory tokensTaken = _transferFromPoolToAddress( @@ -510,6 +482,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { * @dev - decrement `poolBalances.t0Debt` accumulator * @dev - decrement `poolBalances.t0DebtInAuction` accumulator * @dev - decrement `poolBalances.pledgedCollateral` accumulator + * @dev - update `t0Debt2ToCollateral` ratio only if auction settled, debt and collateral pre action are considered 0 */ function bucketTake( address borrowerAddress_, @@ -519,7 +492,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { PoolState memory poolState = _accruePoolInterest(); - BucketTakeResult memory result = TakerActions.bucketTake( + TakeResult memory result = TakerActions.bucketTake( auctions, buckets, deposits, @@ -531,31 +504,7 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool { 1 ); - // update pool balances state - uint256 t0DebtInAuction = poolBalances.t0DebtInAuction; - t0DebtInAuction += result.t0DebtPenalty; - t0DebtInAuction -= result.t0DebtInAuctionChange; - - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction = t0DebtInAuction; - - // the total collateral taken from borrower pledged collateral (collateral taken plus collateral compensated if auction settled) - uint256 collateralSettled = result.collateralAmount + result.compensatedCollateral; - poolBalances.pledgedCollateral -= collateralSettled; - - // adjust t0Debt2ToCollateral ratio - _updateT0Debt2ToCollateral( - result.debtPreAction, - result.debtPostAction, - result.collateralPreAction, - result.collateralPostAction - ); - - // update pool interest rate state - poolState.debt = result.poolDebt; - poolState.t0Debt = result.t0PoolDebt; - poolState.collateral -= collateralSettled; - _updateInterestState(poolState, result.newLup); + _updatePostTakeState(result, poolState); if (result.settledAuction) _rebalanceTokens(borrowerAddress_, result.remainingCollateral); } diff --git a/src/PoolInfoUtils.sol b/src/PoolInfoUtils.sol index a87dbbb42..12be0c303 100644 --- a/src/PoolInfoUtils.sol +++ b/src/PoolInfoUtils.sol @@ -237,7 +237,7 @@ contract PoolInfoUtils { (uint256 bondEscrowed, uint256 unclaimedReserve, uint256 auctionKickTime, ) = pool.reservesInfo(); // due to rounding issues, especially in Auction.settle, this can be slighly negative - if ( poolDebt + quoteTokenBalance >= poolSize + bondEscrowed + unclaimedReserve) { + if (poolDebt + quoteTokenBalance >= poolSize + bondEscrowed + unclaimedReserve) { reserves_ = poolDebt + quoteTokenBalance - poolSize - bondEscrowed - unclaimedReserve; } diff --git a/src/base/Pool.sol b/src/base/Pool.sol index 5b17a397e..b9151472d 100644 --- a/src/base/Pool.sol +++ b/src/base/Pool.sol @@ -37,6 +37,8 @@ import { } from '../interfaces/pool/commons/IPoolState.sol'; import { KickResult, + SettleResult, + TakeResult, RemoveQuoteParams, MoveQuoteParams, AddQuoteParams, @@ -185,7 +187,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { _revertOnExpiry(expiry_); PoolState memory poolState = _accruePoolInterest(); - _revertIfAuctionDebtLocked(deposits, poolBalances, fromIndex_, poolState.inflator); + _revertIfAuctionDebtLocked(deposits, poolState.t0DebtInAuction, fromIndex_, poolState.inflator); uint256 newLup; ( @@ -218,7 +220,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { PoolState memory poolState = _accruePoolInterest(); - _revertIfAuctionDebtLocked(deposits, poolBalances, index_, poolState.inflator); + _revertIfAuctionDebtLocked(deposits, poolState.t0DebtInAuction, index_, poolState.inflator); uint256 newLup; ( @@ -275,6 +277,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { * @inheritdoc IPoolKickerActions * @dev === Write state === * @dev increment `poolBalances.t0DebtInAuction` and `poolBalances.t0Debt` accumulators + * @dev update `t0Debt2ToCollateral` ratio, debt and collateral post action are considered 0 */ function kick( address borrower_, @@ -292,21 +295,23 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { npLimitIndex_ ); - // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction += result.t0KickedDebt; + // update in memory pool state struct + poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator); + poolState.t0Debt = result.t0PoolDebt; + poolState.t0DebtInAuction += result.t0KickedDebt; // adjust t0Debt2ToCollateral ratio _updateT0Debt2ToCollateral( result.debtPreAction, - result.t0KickedDebt, - result.collateralPreAction, // collateral doesn't change when auction is kicked - result.collateralPreAction // collateral doesn't change when auction is kicked + 0, // debt post kick (for loan in auction) not taken into account + result.collateralPreAction, + 0 // collateral post kick (for loan in auction) not taken into account ); + // update pool balances state + poolBalances.t0Debt = poolState.t0Debt; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; // update pool interest rate state - poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator); - poolState.t0Debt = result.t0PoolDebt; _updateInterestState(poolState, result.lup); if (result.amountToCoverBond != 0) _transferQuoteTokenFrom(msg.sender, result.amountToCoverBond); @@ -316,6 +321,7 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { * @inheritdoc IPoolKickerActions * @dev === Write state === * @dev increment `poolBalances.t0DebtInAuction` and `poolBalances.t0Debt` accumulators + * @dev update `t0Debt2ToCollateral` ratio, debt and collateral post action are considered 0 */ function kickWithDeposit( uint256 index_, @@ -334,21 +340,24 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { npLimitIndex_ ); - // update pool balances state - poolBalances.t0Debt = result.t0PoolDebt; - poolBalances.t0DebtInAuction += result.t0KickedDebt; + // update in memory pool state struct + poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator); + poolState.t0Debt = result.t0PoolDebt; + poolState.t0DebtInAuction += result.t0KickedDebt; // adjust t0Debt2ToCollateral ratio _updateT0Debt2ToCollateral( result.debtPreAction, - result.t0KickedDebt, - result.collateralPreAction, // collateral doesn't change when auction is kicked - result.collateralPreAction // collateral doesn't change when auction is kicked + 0, // debt post kick (for loan in auction) not taken into account + result.collateralPreAction, + 0 // collateral post kick (for loan in auction) not taken into account ); + // update pool balances state + poolBalances.t0Debt = poolState.t0Debt; + poolBalances.t0DebtInAuction = poolState.t0DebtInAuction; + // update pool interest rate state - poolState.debt = Maths.wmul(result.t0PoolDebt, poolState.inflator); - poolState.t0Debt = result.t0PoolDebt; _updateInterestState(poolState, result.lup); // transfer from kicker to pool the difference to cover bond @@ -532,12 +541,13 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { * @return poolState_ Struct containing pool details. */ function _accruePoolInterest() internal returns (PoolState memory poolState_) { - poolState_.t0Debt = poolBalances.t0Debt; - poolState_.collateral = poolBalances.pledgedCollateral; - poolState_.inflator = inflatorState.inflator; - poolState_.rate = interestState.interestRate; - poolState_.poolType = _getArgUint8(POOL_TYPE); - poolState_.quoteDustLimit = _getArgUint256(QUOTE_SCALE); + poolState_.t0Debt = poolBalances.t0Debt; + poolState_.t0DebtInAuction = poolBalances.t0DebtInAuction; + poolState_.collateral = poolBalances.pledgedCollateral; + poolState_.inflator = inflatorState.inflator; + poolState_.rate = interestState.interestRate; + poolState_.poolType = _getArgUint8(POOL_TYPE); + poolState_.quoteDustLimit = _getArgUint256(QUOTE_SCALE); // check if t0Debt is not equal to 0, indicating that there is debt to be tracked for the pool if (poolState_.t0Debt != 0) { @@ -569,6 +579,63 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool { } } + /** + * @notice Helper function to update pool state post take and bucket take actions. + * @param result_ Struct containing details of take result. + * @param poolState_ Struct containing pool details. + */ + function _updatePostTakeState( + TakeResult memory result_, + PoolState memory poolState_ + ) internal { + // update in memory pool state struct + poolState_.debt = result_.poolDebt; + poolState_.t0Debt = result_.t0PoolDebt; + poolState_.t0DebtInAuction += result_.t0DebtPenalty; + poolState_.t0DebtInAuction -= result_.t0DebtInAuctionChange; + poolState_.collateral -= (result_.collateralAmount + result_.compensatedCollateral); // deduct collateral taken plus collateral compensated if NFT auction settled + + // adjust t0Debt2ToCollateral ratio if auction settled by take action + if (result_.settledAuction) { + _updateT0Debt2ToCollateral( + 0, // debt pre take (for loan in auction) not taken into account + result_.debtPostAction, + 0, // collateral pre take (for loan in auction) not taken into account + result_.collateralPostAction + ); + } + + // update pool balances state + poolBalances.t0Debt = poolState_.t0Debt; + poolBalances.t0DebtInAuction = poolState_.t0DebtInAuction; + poolBalances.pledgedCollateral = poolState_.collateral; + // update pool interest rate state + _updateInterestState(poolState_, result_.newLup); + } + + /** + * @notice Helper function to update pool state post settle action. + * @param result_ Struct containing details of settle result. + * @param poolState_ Struct containing pool details. + */ + function _updatePostSettleState( + SettleResult memory result_, + PoolState memory poolState_ + ) internal { + // update in memory pool state struct + poolState_.debt -= Maths.wmul(result_.t0DebtSettled, poolState_.inflator); + poolState_.t0Debt -= result_.t0DebtSettled; + poolState_.t0DebtInAuction -= result_.t0DebtSettled; + poolState_.collateral -= result_.collateralSettled; + + // update pool balances state + poolBalances.t0Debt = poolState_.t0Debt; + poolBalances.t0DebtInAuction = poolState_.t0DebtInAuction; + poolBalances.pledgedCollateral = poolState_.collateral; + // update pool interest rate state + _updateInterestState(poolState_, Deposits.getLup(deposits, poolState_.debt)); + } + /** * @notice Adjusts the `t0` debt 2 to collateral ratio, `interestState.t0Debt2ToCollateral`. * @dev Anytime a borrower's debt or collateral changes, the `interestState.t0Debt2ToCollateral` must be updated. diff --git a/src/interfaces/pool/commons/IPoolInternals.sol b/src/interfaces/pool/commons/IPoolInternals.sol index 8a82801db..ad7d6428b 100644 --- a/src/interfaces/pool/commons/IPoolInternals.sol +++ b/src/interfaces/pool/commons/IPoolInternals.sol @@ -10,23 +10,6 @@ pragma solidity 0.8.14; /*** Auction Param Structs ***/ /*****************************/ -/// @dev Struct used to return result of `TakerAction.bucketTake` action. -struct BucketTakeResult { - uint256 collateralAmount; // [WAD] amount of collateral taken - uint256 compensatedCollateral; // [WAD] amount of borrower collateral that is compensated with LP - uint256 t0DebtPenalty; // [WAD] t0 penalty applied on first take - uint256 remainingCollateral; // [WAD] amount of borrower collateral remaining after take - uint256 poolDebt; // [WAD] current pool debt - uint256 t0PoolDebt; // [WAD] t0 pool debt - uint256 newLup; // [WAD] current lup - uint256 t0DebtInAuctionChange; // [WAD] the amount of t0 debt recovered by take action - bool settledAuction; // true if auction is settled by take action - uint256 debtPreAction; // [WAD] The amount of borrower t0 debt before take - uint256 debtPostAction; // [WAD] The amount of borrower t0 debt after take - uint256 collateralPreAction; // [WAD] The amount of borrower collateral before take - uint256 collateralPostAction; // [WAD] The amount of borrower collateral after take -} - /// @dev Struct used to return result of `KickerAction.kick` action. struct KickResult { uint256 amountToCoverBond; // [WAD] amount of bond that needs to be covered @@ -54,13 +37,13 @@ struct SettleResult { uint256 t0DebtSettled; // [WAD] The amount of t0 debt settled } -/// @dev Struct used to return result of `TakerAction.take` action. +/// @dev Struct used to return result of `TakerAction.take` and `TakerAction.bucketTake` actions. struct TakeResult { uint256 collateralAmount; // [WAD] amount of collateral taken uint256 compensatedCollateral; // [WAD] amount of borrower collateral that is compensated with LP - uint256 quoteTokenAmount; // [WAD] amount of quote tokens paid by taker for taken collateral + uint256 quoteTokenAmount; // [WAD] amount of quote tokens paid by taker for taken collateral, used in take action uint256 t0DebtPenalty; // [WAD] t0 penalty applied on first take - uint256 excessQuoteToken; // [WAD] (NFT only) amount of quote tokens to be paid by taker to borrower for fractional collateral + uint256 excessQuoteToken; // [WAD] (NFT only) amount of quote tokens to be paid by taker to borrower for fractional collateral, used in take action uint256 remainingCollateral; // [WAD] amount of borrower collateral remaining after take uint256 poolDebt; // [WAD] current pool debt uint256 t0PoolDebt; // [WAD] t0 pool debt @@ -112,6 +95,7 @@ struct RemoveQuoteParams { /// @dev Struct used to return result of `BorrowerActions.drawDebt` action. struct DrawDebtResult { + bool inAuction; // true if loan still in auction after pledge more collateral, false otherwise uint256 newLup; // [WAD] new pool LUP after draw debt uint256 poolCollateral; // [WAD] total amount of collateral in pool after pledge collateral uint256 poolDebt; // [WAD] total accrued debt in pool after draw debt @@ -127,6 +111,7 @@ struct DrawDebtResult { /// @dev Struct used to return result of `BorrowerActions.repayDebt` action. struct RepayDebtResult { + bool inAuction; // true if loan still in auction after repay, false otherwise uint256 newLup; // [WAD] new pool LUP after draw debt uint256 poolCollateral; // [WAD] total amount of collateral in pool after pull collateral uint256 poolDebt; // [WAD] total accrued debt in pool after repay debt diff --git a/src/interfaces/pool/commons/IPoolState.sol b/src/interfaces/pool/commons/IPoolState.sol index 46356542c..d0d978476 100644 --- a/src/interfaces/pool/commons/IPoolState.sol +++ b/src/interfaces/pool/commons/IPoolState.sol @@ -330,6 +330,7 @@ struct PoolBalancesState { struct PoolState { uint8 poolType; // pool type, can be ERC20 or ERC721 uint256 t0Debt; // [WAD] t0 debt in pool + uint256 t0DebtInAuction; // [WAD] t0 debt in auction within pool uint256 debt; // [WAD] total debt in pool, accrued in current block uint256 collateral; // [WAD] total collateral pledged in pool uint256 inflator; // [WAD] current pool inflator diff --git a/src/libraries/external/BorrowerActions.sol b/src/libraries/external/BorrowerActions.sol index e0afd63c0..c05e4530b 100644 --- a/src/libraries/external/BorrowerActions.sol +++ b/src/libraries/external/BorrowerActions.sol @@ -50,7 +50,6 @@ library BorrowerActions { uint256 compensatedCollateral; // [WAD] amount of borrower collateral that is compensated with LP (NFTs only) uint256 t0BorrowAmount; // [WAD] t0 amount to borrow uint256 t0DebtChange; // [WAD] additional t0 debt resulted from draw debt action - bool inAuction; // true if loan is auctioned bool pledge; // true if pledge action bool stampT0Np; // true if loan's t0 neutral price should be restamped (when drawing debt or pledge settles auction) } @@ -59,7 +58,6 @@ library BorrowerActions { struct RepayDebtLocalVars { uint256 borrowerDebt; // [WAD] borrower's accrued debt uint256 compensatedCollateral; // [WAD] amount of borrower collateral that is compensated with LP (NFTs only) - bool inAuction; // true if loan still in auction after repay, false otherwise bool pull; // true if pull action bool repay; // true if repay action bool stampT0Np; // true if loan's t0 neutral price should be restamped (when repay settles auction or pull collateral) @@ -134,8 +132,8 @@ library BorrowerActions { Borrower memory borrower = loans_.borrowers[borrowerAddress_]; vars.borrowerDebt = Maths.wmul(borrower.t0Debt, poolState_.inflator); - vars.inAuction = _inAuction(auctions_, borrowerAddress_); + result_.inAuction = _inAuction(auctions_, borrowerAddress_); result_.debtPreAction = borrower.t0Debt; result_.collateralPreAction = borrower.collateral; result_.t0PoolDebt = poolState_.t0Debt; @@ -152,15 +150,15 @@ library BorrowerActions { // if loan is auctioned and becomes collateralized by newly pledged collateral then settle auction if ( - vars.inAuction && + result_.inAuction && _isCollateralized(vars.borrowerDebt, borrower.collateral, result_.newLup, poolState_.poolType) ) { - // borrower becomes collateralized - vars.inAuction = false; - vars.stampT0Np = true; // stamp borrower t0Np when exiting from auction + // stamp borrower t0Np when exiting from auction + vars.stampT0Np = true; - result_.settledAuction = true; - // remove debt from pool accumulator and settle auction + // borrower becomes re-collateralized, entire borrower debt is removed from pool auctions debt accumulator + result_.inAuction = false; + result_.settledAuction = true; result_.t0DebtInAuctionChange = borrower.t0Debt; // settle auction and update borrower's collateral with value after settlement @@ -175,10 +173,9 @@ library BorrowerActions { borrower.collateral, poolState_.poolType ); - - borrower.collateral = result_.remainingCollateral; - result_.poolCollateral -= vars.compensatedCollateral; + + borrower.collateral = result_.remainingCollateral; } // add new amount of collateral to pledge to pool balance @@ -190,7 +187,7 @@ library BorrowerActions { if (borrowerAddress_ != msg.sender) revert BorrowerNotSender(); // an auctioned borrower in not allowed to draw more debt (even if collateralized at the new LUP) if auction is not settled - if (vars.inAuction) revert AuctionActive(); + if (result_.inAuction) revert AuctionActive(); vars.t0BorrowAmount = Maths.wdiv(amountToBorrow_, poolState_.inflator); @@ -238,7 +235,7 @@ library BorrowerActions { result_.poolDebt, poolState_.rate, result_.newLup, - vars.inAuction, + result_.inAuction, vars.stampT0Np ); @@ -290,8 +287,8 @@ library BorrowerActions { Borrower memory borrower = loans_.borrowers[borrowerAddress_]; vars.borrowerDebt = Maths.wmul(borrower.t0Debt, poolState_.inflator); - vars.inAuction = _inAuction(auctions_, borrowerAddress_); + result_.inAuction = _inAuction(auctions_, borrowerAddress_); result_.debtPreAction = borrower.t0Debt; result_.collateralPreAction = borrower.collateral; result_.t0PoolDebt = poolState_.t0Debt; @@ -328,14 +325,14 @@ library BorrowerActions { result_.newLup = Deposits.getLup(deposits_, result_.poolDebt); // if loan is auctioned and becomes collateralized by repaying debt then settle auction - if (vars.inAuction) { + if (result_.inAuction) { if (_isCollateralized(vars.borrowerDebt, borrower.collateral, result_.newLup, poolState_.poolType)) { - // borrower becomes re-collateralized - vars.inAuction = false; - vars.stampT0Np = true; // stamp borrower t0Np when exiting from auction + // stamp borrower t0Np when exiting from auction + vars.stampT0Np = true; - result_.settledAuction = true; - // remove entire borrower debt from pool auctions debt accumulator + // borrower becomes re-collateralized, entire borrower debt is removed from pool auctions debt accumulator + result_.inAuction = false; + result_.settledAuction = true; result_.t0DebtInAuctionChange = borrower.t0Debt; // settle auction and update borrower's collateral with value after settlement @@ -350,10 +347,9 @@ library BorrowerActions { borrower.collateral, poolState_.poolType ); + result_.poolCollateral -= vars.compensatedCollateral; borrower.collateral = result_.remainingCollateral; - - result_.poolCollateral -= vars.compensatedCollateral; } else { // partial repay, remove only the paid debt from pool auctions debt accumulator result_.t0DebtInAuctionChange = vars.t0RepaidDebt; @@ -368,7 +364,7 @@ library BorrowerActions { if (borrowerAddress_ != msg.sender) revert BorrowerNotSender(); // an auctioned borrower in not allowed to pull collateral (even if collateralized at the new LUP) if auction is not settled - if (vars.inAuction) revert AuctionActive(); + if (result_.inAuction) revert AuctionActive(); // calculate LUP only if it wasn't calculated in repay action if (!vars.repay) result_.newLup = Deposits.getLup(deposits_, result_.poolDebt); @@ -400,7 +396,7 @@ library BorrowerActions { result_.poolDebt, poolState_.rate, result_.newLup, - vars.inAuction, + result_.inAuction, vars.stampT0Np ); diff --git a/src/libraries/external/PoolCommons.sol b/src/libraries/external/PoolCommons.sol index 82bda1f20..c3dea3b5e 100644 --- a/src/libraries/external/PoolCommons.sol +++ b/src/libraries/external/PoolCommons.sol @@ -63,6 +63,7 @@ library PoolCommons { int256 weightMau; int256 weightTu; uint256 newInterestRate; + uint256 nonAuctionedT0Debt; } /**************************/ @@ -96,56 +97,60 @@ library PoolCommons { vars.t0Debt2ToCollateral = interestParams_.t0Debt2ToCollateral; // calculate new interest params - vars.newDebt = poolState_.debt; + vars.nonAuctionedT0Debt = poolState_.t0Debt - poolState_.t0DebtInAuction; + vars.newDebt = Maths.wmul(vars.nonAuctionedT0Debt, poolState_.inflator); // new meaningful deposit cannot be less than pool's debt vars.newMeaningfulDeposit = Maths.max( _meaningfulDeposit( deposits_, - poolState_.t0Debt, + poolState_.t0DebtInAuction, + vars.nonAuctionedT0Debt, poolState_.inflator, vars.t0Debt2ToCollateral ), vars.newDebt ); vars.newDebtCol = Maths.wmul(poolState_.inflator, vars.t0Debt2ToCollateral); - vars.newLupt0Debt = Maths.wmul(lup_, poolState_.t0Debt); + vars.newLupt0Debt = Maths.wmul(lup_, vars.nonAuctionedT0Debt); // update EMAs only once per block if (vars.lastEmaUpdate != block.timestamp) { - // We do not need to calculate these during initialization, - // but the conditional to check each time would be more expensive thereafter. - vars.elapsed = int256(Maths.wdiv(block.timestamp - vars.lastEmaUpdate, 1 hours)); - vars.weightMau = PRBMathSD59x18.exp(PRBMathSD59x18.mul(NEG_H_MAU_HOURS, vars.elapsed)); - vars.weightTu = PRBMathSD59x18.exp(PRBMathSD59x18.mul(NEG_H_TU_HOURS, vars.elapsed)); - - // calculate the t0 debt EMA, used for MAU - vars.debtEma = vars.debtEma == 0 ? vars.newDebt : - uint256( + // first time EMAs are updated, initialize EMAs + if (vars.lastEmaUpdate == 0) { + vars.debtEma = vars.newDebt; + vars.depositEma = vars.newMeaningfulDeposit; + vars.debtColEma = vars.newDebtCol; + vars.lupt0DebtEma = vars.newLupt0Debt; + } else { + vars.elapsed = int256(Maths.wdiv(block.timestamp - vars.lastEmaUpdate, 1 hours)); + vars.weightMau = PRBMathSD59x18.exp(PRBMathSD59x18.mul(NEG_H_MAU_HOURS, vars.elapsed)); + vars.weightTu = PRBMathSD59x18.exp(PRBMathSD59x18.mul(NEG_H_TU_HOURS, vars.elapsed)); + + // calculate the t0 debt EMA, used for MAU + vars.debtEma = uint256( PRBMathSD59x18.mul(vars.weightMau, int256(vars.debtEma)) + PRBMathSD59x18.mul(1e18 - vars.weightMau, int256(interestParams_.debt)) ); - // update the meaningful deposit EMA, used for MAU - vars.depositEma = vars.depositEma == 0 ? vars.newMeaningfulDeposit : - uint256( + // update the meaningful deposit EMA, used for MAU + vars.depositEma = uint256( PRBMathSD59x18.mul(vars.weightMau, int256(vars.depositEma)) + PRBMathSD59x18.mul(1e18 - vars.weightMau, int256(interestParams_.meaningfulDeposit)) ); - // calculate the debt squared to collateral EMA, used for TU - vars.debtColEma = vars.debtColEma == 0 ? vars.newDebtCol : - uint256( + // calculate the debt squared to collateral EMA, used for TU + vars.debtColEma = uint256( PRBMathSD59x18.mul(vars.weightTu, int256(vars.debtColEma)) + PRBMathSD59x18.mul(1e18 - vars.weightTu, int256(interestParams_.debtCol)) ); - // calculate the EMA of LUP * t0 debt - vars.lupt0DebtEma = vars.lupt0DebtEma == 0 ? vars.newLupt0Debt : - uint256( + // calculate the EMA of LUP * t0 debt + vars.lupt0DebtEma = uint256( PRBMathSD59x18.mul(vars.weightTu, int256(vars.lupt0DebtEma)) + PRBMathSD59x18.mul(1e18 - vars.weightTu, int256(interestParams_.lupt0Debt)) ); + } // save EMAs in storage emaParams_.debtEma = vars.debtEma; @@ -335,13 +340,23 @@ library PoolCommons { } } + /** + * @notice Calculates pool's meaningful deposit. + * @param deposits_ Struct for pool deposits state. + * @param t0DebtInAuction_ Value of pool's t0 debt currently in auction. + * @param nonAuctionedT0Debt_ Value of pool's t0 debt that is not in auction. + * @param inflator_ Pool's current inflator. + * @param t0Debt2ToCollateral_ `t0Debt2ToCollateral` ratio. + * @return meaningfulDeposit_ Pool's meaningful deposit. + */ function _meaningfulDeposit( DepositsState storage deposits_, - uint256 t0Debt_, + uint256 t0DebtInAuction_, + uint256 nonAuctionedT0Debt_, uint256 inflator_, uint256 t0Debt2ToCollateral_ ) internal view returns (uint256 meaningfulDeposit_) { - uint256 dwatp = _dwatp(t0Debt_, inflator_, t0Debt2ToCollateral_); + uint256 dwatp = _dwatp(nonAuctionedT0Debt_, inflator_, t0Debt2ToCollateral_); if (dwatp == 0) { meaningfulDeposit_ = Deposits.treeSum(deposits_); } else { @@ -349,6 +364,7 @@ library PoolCommons { else if (dwatp >= MIN_PRICE) meaningfulDeposit_ = Deposits.prefixSum(deposits_, _indexOf(dwatp)); else meaningfulDeposit_ = Deposits.treeSum(deposits_); } + meaningfulDeposit_ -= Maths.min(meaningfulDeposit_, t0DebtInAuction_); } /**********************/ diff --git a/src/libraries/external/SettlerActions.sol b/src/libraries/external/SettlerActions.sol index 2075d668d..0393ea8b0 100644 --- a/src/libraries/external/SettlerActions.sol +++ b/src/libraries/external/SettlerActions.sol @@ -466,13 +466,13 @@ library SettlerActions { Bucket storage hpbBucket = buckets_[index]; if (hpbBucket.collateral == 0) { // existing LP for the bucket shall become unclaimable - hpbBucket.lps = 0; - hpbBucket.bankruptcyTime = block.timestamp; - emit BucketBankruptcy( index, hpbBucket.lps ); + + hpbBucket.lps = 0; + hpbBucket.bankruptcyTime = block.timestamp; } } diff --git a/src/libraries/external/TakerActions.sol b/src/libraries/external/TakerActions.sol index eb59d6705..44b5ed1fb 100644 --- a/src/libraries/external/TakerActions.sol +++ b/src/libraries/external/TakerActions.sol @@ -18,7 +18,6 @@ import { ReserveAuctionState } from '../../interfaces/pool/commons/IPoolState.sol'; import { - BucketTakeResult, TakeResult } from '../../interfaces/pool/commons/IPoolInternals.sol'; @@ -128,7 +127,7 @@ library TakerActions { * @notice Performs bucket take collateral on an auction, rewards taker and kicker (if case) and updates loan info (settles auction if case). * @dev === Reverts on === * @dev not enough collateral to take `InsufficientCollateral()` - * @return result_ `BucketTakeResult` struct containing details of bucket take result. + * @return result_ `TakeResult` struct containing details of bucket take result. */ function bucketTake( AuctionsState storage auctions_, @@ -140,7 +139,7 @@ library TakerActions { bool depositTake_, uint256 index_, uint256 collateralScale_ - ) external returns (BucketTakeResult memory result_) { + ) external returns (TakeResult memory result_) { Borrower memory borrower = loans_.borrowers[borrowerAddress_]; if (borrower.collateral == 0) revert InsufficientCollateral(); // revert if borrower's collateral is 0 diff --git a/src/libraries/helpers/RevertsHelper.sol b/src/libraries/helpers/RevertsHelper.sol index fa04283bf..e51b2ba70 100644 --- a/src/libraries/helpers/RevertsHelper.sol +++ b/src/libraries/helpers/RevertsHelper.sol @@ -27,19 +27,19 @@ import { Maths } from '../internal/Maths.sol'; /** * @notice Called by `LP` removal functions assess whether or not `LP` is locked. * @dev Reverts with `RemoveDepositLockedByAuctionDebt` if debt locked. - * @param index_ The deposit index from which `LP` is attempting to be removed. - * @param inflator_ The pool inflator used to properly assess t0 debt in auctions. + * @param t0DebtInAuction_ Pool's t0 debt currently in auction. + * @param index_ The deposit index from which `LP` is attempting to be removed. + * @param inflator_ The pool inflator used to properly assess t0 debt in auctions. */ function _revertIfAuctionDebtLocked( DepositsState storage deposits_, - PoolBalancesState storage poolBalances_, + uint256 t0DebtInAuction_, uint256 index_, uint256 inflator_ ) view { - uint256 t0AuctionDebt = poolBalances_.t0DebtInAuction; - if (t0AuctionDebt != 0 ) { + if (t0DebtInAuction_ != 0 ) { // deposit in buckets within liquidation debt from the top-of-book down are frozen. - if (index_ <= Deposits.findIndexOfSum(deposits_, Maths.wmul(t0AuctionDebt, inflator_))) revert RemoveDepositLockedByAuctionDebt(); + if (index_ <= Deposits.findIndexOfSum(deposits_, Maths.wmul(t0DebtInAuction_, inflator_))) revert RemoveDepositLockedByAuctionDebt(); } } diff --git a/tests/INVARIANTS.md b/tests/INVARIANTS.md index 652ffa667..de5573e49 100644 --- a/tests/INVARIANTS.md +++ b/tests/INVARIANTS.md @@ -42,7 +42,7 @@ - **I1**: interest rate (`InterestState.interestRate`) cannot be updated more than once in a 12 hours period of time (`InterestState.interestRateUpdate`) - **I2**: reserve interest (`ReserveAuctionState.totalInterestEarned`) accrues only once per block (`block.timestamp - InflatorState.inflatorUpdate != 0`) and only if there's debt in the pool (`PoolBalancesState.t0Debt != 0`) - **I3**: pool inflator (`InflatorState.inflator`) cannot be updated more than once per block (`block.timestamp - InflatorState.inflatorUpdate != 0`) and equals `1e18` if there's no debt in the pool (`PoolBalancesState.t0Debt != 0`) -- **I4**: for all borrowers where (`borrower.collateral != 0`) the sum of borrower debt squared divided by borrower collateral (`borrower.debt^2 / borrower.collateral`) should equal borrower collateralization accumulator (`t0Debt2ToCollateral`) +- **I4**: for all borrowers that are not auctioned and (`borrower.collateral != 0`) the sum of borrower debt squared divided by borrower collateral (`borrower.debt^2 / borrower.collateral`) should equal borrower collateralization accumulator (`t0Debt2ToCollateral`) ## Fenwick tree - **F1**: Value represented at index `i` (`Deposits.valueAt(i)`) is equal to the accumulation of scaled values incremented or decremented from index `i` diff --git a/tests/forge/invariants/base/BasicInvariants.t.sol b/tests/forge/invariants/base/BasicInvariants.t.sol index afbc23517..4b428a7af 100644 --- a/tests/forge/invariants/base/BasicInvariants.t.sol +++ b/tests/forge/invariants/base/BasicInvariants.t.sol @@ -239,11 +239,15 @@ abstract contract BasicInvariants is BaseInvariants { for (uint256 i = 0; i < actorCount; i++) { address borrower = IBaseHandler(_handler).actors(i); - (uint256 borrowerT0Debt, uint256 borrowerCollateral, ) = _pool.borrowerInfo(borrower); - uint256 weight = borrowerCollateral != 0 ? borrowerT0Debt ** 2 / borrowerCollateral : 0; + (, , , uint256 kickTime, , , , , , ) = _pool.auctionInfo(borrower); - manualDebt2ToCollateral += weight; + if (kickTime == 0) { + (uint256 borrowerT0Debt, uint256 borrowerCollateral, ) = _pool.borrowerInfo(borrower); + uint256 weight = borrowerCollateral != 0 ? borrowerT0Debt ** 2 / borrowerCollateral : 0; + + manualDebt2ToCollateral += weight; + } } (,,, uint256 t0Debt2ToCollateral) = _pool.debtInfo(); diff --git a/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol b/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol index 7637d31be..007ee6ca9 100644 --- a/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol +++ b/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol @@ -292,7 +292,7 @@ contract RegressionTestLiquidationERC20Pool is LiquidationERC20PoolInvariants { } // Test reverting with overflow error in dwatp calculation in _meaningfulDeposit in updateInterestState - function _test_regression_evm_revert_2() external { + function test_regression_evm_revert_2() external { _liquidationERC20PoolHandler.drawDebt(13141077791835967310451371165744721774, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 0); _liquidationERC20PoolHandler.kickAuction(3, 53758605435723729358784, 3, 0); _liquidationERC20PoolHandler.repayDebt(668608315443216098571064749198163965820, 18932325376258851353179065817321260901, 0); diff --git a/tests/forge/regression/ERC20Pool/RegressionTestReservesERC20Pool.t.sol b/tests/forge/regression/ERC20Pool/RegressionTestReservesERC20Pool.t.sol index 73a2688e5..46aff4464 100644 --- a/tests/forge/regression/ERC20Pool/RegressionTestReservesERC20Pool.t.sol +++ b/tests/forge/regression/ERC20Pool/RegressionTestReservesERC20Pool.t.sol @@ -435,7 +435,7 @@ contract RegressionTestReserveERC20Pool is ReserveERC20PoolInvariants { Test was reverting when redeemedLps = bucketLps but lenderlps < redeemedLps, this happens due to slight rounding error in deposit calculation from lps Fixed by updating redeemedLP calculations to `vars.redeemedLP = Maths.min(lender.lps, vars.redeemedLP)` */ - function _test_regression_evm_revert_2() external { + function test_regression_evm_revert_2() external { _reserveERC20PoolHandler.moveQuoteToken(1, 2, 115792089237316195423570985008687907853269984665640564039457584007913129639932, 158129467307529830729349478455, 0); _reserveERC20PoolHandler.removeQuoteToken(2999999999999999484865294266928579000517539849, 20462, 1576762402919713971836094859031, 0); _reserveERC20PoolHandler.takeReserves(115792089237316195423570985008687907853269984665640564039457584007913129639935, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 0); @@ -458,7 +458,7 @@ contract RegressionTestReserveERC20Pool is ReserveERC20PoolInvariants { Test was reverting with overflow in `(tu + mau102 - 1e18) ** 2)` calculation in _calculateInterestRate Fixed by updating `((tu + mau102 - 1e18) ** 2) / 1e18` to `(((tu + mau102 - 1e18) / 1e9) ** 2)` */ - function _test_regression_evm_revert_3() external { + function test_regression_evm_revert_3() external { _reserveERC20PoolHandler.drawDebt(1000011592650618236, 427626464706163901647666438633, 0); _reserveERC20PoolHandler.takeReserves(115792089237316195423570985008687907853269984665640564039457584007913129639933, 1, 0); _reserveERC20PoolHandler.repayDebt(115792089237316195423570985008687907853269984665640564039457584007913129639934, 222282777921247831223488066461, 0); @@ -480,4 +480,26 @@ contract RegressionTestReserveERC20Pool is ReserveERC20PoolInvariants { _reserveERC20PoolHandler.transferLps(2999999999999999866089865785362154170272346882, 1201303985144971, 3000000000000000000069282600099281847535823208, 2516, 0); _reserveERC20PoolHandler.kickAuction(11585421328272707882885111971840751049901594256465502255118203311426017450, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 0); } + + // Test reverting with overflow error in updateInterestState, fixed with calculating t0Debt2ToCollateral only for loans not in auction + function test_regression_evm_revert_dwatp_calculation() external { + _reserveERC20PoolHandler.takeAuction(50273692421744377186963564518293270398423601950557187270240, 2548824763847568430445964332385997581867729, 2, 0); + _reserveERC20PoolHandler.drawDebt(115792089237316195423570985008687907853269984665640564039457584007913129639933, 2, 0); + _reserveERC20PoolHandler.bucketTake(2, 178384181005, false, 6392753955405727164548240817297990606823468910265481812293128708, 0); + _reserveERC20PoolHandler.removeQuoteToken(3782769546571580286491282490173426994, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 54687167, 0); + _reserveERC20PoolHandler.settleAuction(39578, 1, 6177214753589, 0); + _reserveERC20PoolHandler.repayDebt(1025386930210936368, 4259484542182884235320983165905627435543345198090251871456881749143615, 0); + _reserveERC20PoolHandler.addQuoteToken(115792089237316195423570985008687907853269984665640564039457584007913129639932, 9515050199665708690603228437, 8324830839682368611784829482626590763014978434217970848520, 0); + _reserveERC20PoolHandler.pledgeCollateral(0, 61432102823246505619, 0); + _reserveERC20PoolHandler.kickReserveAuction(90632424972185451325878827725, 0); + _reserveERC20PoolHandler.moveQuoteToken(115792089237316195423570985008687907853269984665640564039457584007913129639933, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 0); + _reserveERC20PoolHandler.removeQuoteToken(662383544472518305626297967684, 417256349487250392122120746762550, 11019, 0); + _reserveERC20PoolHandler.settleAuction(818097782230726263131224806387432801887947892950801, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 0); + _reserveERC20PoolHandler.settleAuction(1045174129353233337547, 14962, 490775706239416317157126137000, 0); + _reserveERC20PoolHandler.removeCollateral(115792089237316195423570985008687907853269984665640564039457584007913129639934, 0, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 0); + _reserveERC20PoolHandler.removeQuoteToken(7138, 27260, 5841, 0); + _reserveERC20PoolHandler.bucketTake(130086595647608623733586123, 0, false, 2, 0); + _reserveERC20PoolHandler.pledgeCollateral(115792089237316195423570985008687907853269984665640564039457584007913129639933, 1, 0); + _reserveERC20PoolHandler.settleAuction(877519612062733, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 3, 0); + } } diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolBorrow.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolBorrow.t.sol index 42f74eaa1..3231a5bf5 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolBorrow.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolBorrow.t.sol @@ -329,7 +329,7 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { newLup: 2_981.007422784467321543 * 1e18 }); - uint256 expectedDebt = 21_051.890446235135648008 * 1e18; + uint256 expectedDebt = 21_046.123595032677924433 * 1e18; _assertPool( PoolParams({ @@ -337,14 +337,14 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { lup: 2_981.007422784467321543 * 1e18, poolSize: 50_000 * 1e18, pledgedCollateral: 50 * 1e18, - encumberedCollateral: 7.062005376213123432 * 1e18, + encumberedCollateral: 7.060070845235984474 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.420404166896771338 * 1e18, - targetUtilization: 0.141027440233999772 * 1e18, - minDebtAmount: 2_105.189044623513564801 * 1e18, + actualUtilization: 0.000000000000000000 * 1e18, + targetUtilization: 1.000000000000000000 * 1e18, + minDebtAmount: 2_104.612359503267792443 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.055 * 1e18, + interestRate: 0.045 * 1e18, interestRateUpdate: _startTime + 10 days }) ); @@ -353,7 +353,7 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrowerDebt: expectedDebt, borrowerCollateral: 50 * 1e18, borrowert0Np: 441.424038461538461742 * 1e18, - borrowerCollateralization: 7.080141877038845214 * 1e18 + borrowerCollateralization: 7.082081907682151400 * 1e18 }); skip(10 days); @@ -364,22 +364,22 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { amount: 10 * 1e18 }); - expectedDebt = 21_083.636385101213387311 * 1e18; + expectedDebt = 21_072.086872169016071672 * 1e18; _assertPool( PoolParams({ - htp: 351.393939751686889789 * 1e18, + htp: 351.201447869483601195 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 50_055.509494601600650000 * 1e18, + poolSize: 50_044.110379805202100000 * 1e18, pledgedCollateral: 60 * 1e18, - encumberedCollateral: 7.072654775682389039 * 1e18, + encumberedCollateral: 7.068780409975037237 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.420403846154152038 * 1e18, + actualUtilization: 0.420403445225801443 * 1e18, targetUtilization: 0.141027440233999772 * 1e18, - minDebtAmount: 2_108.363638510121338731 * 1e18, + minDebtAmount: 2_107.208687216901607167 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.0605 * 1e18, + interestRate: 0.0495 * 1e18, interestRateUpdate: _startTime + 10 days + 10 days }) ); @@ -388,9 +388,9 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrowerDebt: expectedDebt, borrowerCollateral: 60 * 1e18, borrowert0Np: 441.424038461538461742 * 1e18, - borrowerCollateralization: 8.483377444958217435 * 1e18 + borrowerCollateralization: 8.488027144729466085 * 1e18 }); - _assertLenderInterest(liquidityAdded, 55.509494601600650000 * 1e18); + _assertLenderInterest(liquidityAdded, 44.110379805202100000 * 1e18); skip(10 days); @@ -402,22 +402,22 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { collateralToPull: 10 * 1e18 }); - expectedDebt = 21_118.612213260575680078 * 1e18; + expectedDebt = 21_100.683472334824303370 * 1e18; _assertPool( PoolParams({ - htp: 422.372244265211513602 * 1e18, + htp: 422.013669446696486067 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 50_086.111097974181050000 * 1e18, + poolSize: 50_069.130567554535450000 * 1e18, pledgedCollateral: 50 * 1e18, - encumberedCollateral: 7.084387664333398317 * 1e18, + encumberedCollateral: 7.078373341528054648 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.421205109283081156 * 1e18, - targetUtilization: 0.121072519391563216 * 1e18, - minDebtAmount: 2_111.861221326057568008 * 1e18, + actualUtilization: 0.421070265420802644 * 1e18, + targetUtilization: 0.120628314442263426 * 1e18, + minDebtAmount: 2_110.068347233482430337 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.06655 * 1e18, + interestRate: 0.05445 * 1e18, interestRateUpdate: _startTime + 30 days }) ); @@ -425,10 +425,10 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrower: _borrower, borrowerDebt: expectedDebt, borrowerCollateral: 50 * 1e18, - borrowert0Np: 445.838278846153846359 * 1e18, - borrowerCollateralization: 7.057773002983275247 * 1e18 + borrowert0Np: 441.213836538461538664 * 1e18, + borrowerCollateralization: 7.063769822178689107 * 1e18 }); - _assertLenderInterest(liquidityAdded, 86.111097974181050000 * 1e18); + _assertLenderInterest(liquidityAdded, 69.130567554535450000 * 1e18); skip(10 days); @@ -437,22 +437,22 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { emit LoanStamped(_borrower); _pool.stampLoan(); - expectedDebt = 21_157.152643010853304038 * 1e18; + expectedDebt = 21_132.184557783880298440 * 1e18; _assertPool( PoolParams({ - htp: 423.143052860217066081 * 1e18, + htp: 422.643691155677605969 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 50_119.833720983122450000 * 1e18, + poolSize: 50_096.693504733499050000 * 1e18, pledgedCollateral: 50 * 1e18, - encumberedCollateral: 7.097316323771045135 * 1e18, + encumberedCollateral: 7.088940603188755848 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.421646075713482024 * 1e18, - targetUtilization: 0.138842620340978204 * 1e18, - minDebtAmount: 2_115.715264301085330404 * 1e18, + actualUtilization: 0.421430993826609139 * 1e18, + targetUtilization: 0.138725200998853604 * 1e18, + minDebtAmount: 2_113.218455778388029844 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.073205 * 1e18, + interestRate: 0.059895 * 1e18, interestRateUpdate: _startTime + 40 days }) ); @@ -460,31 +460,31 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrower: _borrower, borrowerDebt: expectedDebt, borrowerCollateral: 50 * 1e18, - borrowert0Np: 448.381722115384615591 * 1e18, - borrowerCollateralization: 7.044916376706357984 * 1e18 + borrowert0Np: 443.294835576923077127 * 1e18, + borrowerCollateralization: 7.053240081812639175 * 1e18 }); - _assertLenderInterest(liquidityAdded, 119.833720983122450000 * 1e18); + _assertLenderInterest(liquidityAdded, 96.693504733499050000 * 1e18); skip(10 days); _updateInterest(); - expectedDebt = 21_199.628356897284442294 * 1e18; + expectedDebt = 21_166.890071570436649845 * 1e18; _assertPool( PoolParams({ - htp: 423.992567137945688846 * 1e18, + htp: 423.337801431408732997 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 50_157.001040562732600000 * 1e18, + poolSize: 50_127.061165904636850000 * 1e18, pledgedCollateral: 50 * 1e18, - encumberedCollateral: 7.111565102073903530 * 1e18, + encumberedCollateral: 7.100582812973708010 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.422131341009898326 * 1e18, - targetUtilization: 0.141517980300850494 * 1e18, - minDebtAmount: 2_119.962835689728444229 * 1e18, + actualUtilization: 0.421827930356991768 * 1e18, + targetUtilization: 0.141358334848097873 * 1e18, + minDebtAmount: 2_116.689007157043664985 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.0805255 * 1e18, + interestRate: 0.0658845 * 1e18, interestRateUpdate: _startTime + 50 days }) ); @@ -492,29 +492,29 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrower: _borrower, borrowerDebt: expectedDebt, borrowerCollateral: 50 * 1e18, - borrowert0Np: 448.381722115384615591 * 1e18, - borrowerCollateralization: 7.030801136225104190 * 1e18 + borrowert0Np: 443.294835576923077127 * 1e18, + borrowerCollateralization: 7.041675495797803839 * 1e18 }); - _assertLenderInterest(liquidityAdded, 157.001040562732600000 * 1e18); + _assertLenderInterest(liquidityAdded, 127.061165904636850000 * 1e18); skip(10 days); - expectedDebt = 21_246.450141935843866714 * 1e18; + expectedDebt = 21_205.131971958652447704 * 1e18; _assertPool( PoolParams({ - htp: 423.992567137945688846 * 1e18, + htp: 423.337801431408732997 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 50_157.001040562732600000 * 1e18, + poolSize: 50_127.061165904636850000 * 1e18, pledgedCollateral: 50 * 1e18, - encumberedCollateral: 7.127271800648583574 * 1e18, + encumberedCollateral: 7.113411328627820409 * 1e18, poolDebt: expectedDebt, - actualUtilization: 0.422131341009898326 * 1e18, - targetUtilization: 0.141517980300850494 * 1e18, - minDebtAmount: 2_124.645014193584386671 * 1e18, + actualUtilization: 0.421827930356991768 * 1e18, + targetUtilization: 0.141358334848097873 * 1e18, + minDebtAmount: 2_120.513197195865244770 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.0805255 * 1e18, + interestRate: 0.0658845 * 1e18, interestRateUpdate: _startTime + 50 days }) ); @@ -523,8 +523,8 @@ contract ERC20PoolBorrowTest is ERC20HelperContract { borrower: _borrower, borrowerDebt: expectedDebt, borrowerCollateral: 50 * 1e18, - borrowert0Np: 448.381722115384615591 * 1e18, - borrowerCollateralization: 7.015307034516347067 * 1e18 + borrowert0Np: 443.294835576923077127 * 1e18, + borrowerCollateralization: 7.028976350457301320 * 1e18 }); } diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolCollateral.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolCollateral.t.sol index 05f74af08..49528fa4c 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolCollateral.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolCollateral.t.sol @@ -131,8 +131,8 @@ contract ERC20PoolCollateralTest is ERC20HelperContract { pledgedCollateral: 50 * 1e18, encumberedCollateral: 7.061038044473493202 * 1e18, poolDebt: 21_049.0068231390029184310 * 1e18, - actualUtilization: 0.701634006858188002 * 1e18, - targetUtilization: 0.141220760889469864 * 1e18, + actualUtilization: 0.700672854184962757 * 1e18, + targetUtilization: 0.070513720116999886 * 1e18, minDebtAmount: 2_104.900682313900291843 * 1e18, loans: 1, maxBorrower: _borrower, @@ -167,8 +167,8 @@ contract ERC20PoolCollateralTest is ERC20HelperContract { pledgedCollateral: 7.061038044473493202 * 1e18, encumberedCollateral: 7.061038044473493202 * 1e18, poolDebt: 21_049.0068231390029184310 * 1e18, - actualUtilization: 0.701634006858188002 * 1e18, - targetUtilization: 0.141220760889469864 * 1e18, + actualUtilization: 0.700672854184962757 * 1e18, + targetUtilization: 0.070513720116999886 * 1e18, minDebtAmount: 2_104.900682313900291843 * 1e18, loans: 1, maxBorrower: _borrower, diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolInterestRateAndEMAs.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolInterestRateAndEMAs.t.sol index e787b6f2a..cc346b17d 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolInterestRateAndEMAs.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolInterestRateAndEMAs.t.sol @@ -82,7 +82,7 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { changePrank(_borrower); vm.expectEmit(true, true, false, true); - emit UpdateInterestRate(0.05 * 1e18, 0.055 * 1e18); + emit UpdateInterestRate(0.05 * 1e18, 0.045 * 1e18); _drawDebtNoLupCheck({ from: _borrower, borrower: _borrower, @@ -97,21 +97,21 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { lup: 2_981.007422784467321543 * 1e18, poolSize: 110_000 * 1e18, pledgedCollateral: 100 * 1e18, - encumberedCollateral: 15.469154633609698947 * 1e18, - poolDebt: 46_113.664786991249514684 * 1e18, - actualUtilization: 0.418584278986712558 * 1e18, - targetUtilization: 0.154458625018190226 * 1e18, - minDebtAmount: 4_611.366478699124951468 * 1e18, + encumberedCollateral: 15.464917089564537419 * 1e18, + poolDebt: 46_101.032636738246882092 * 1e18, + actualUtilization: 0.000000000000000000 * 1e18, + targetUtilization: 1.000000000000000000 * 1e18, + minDebtAmount: 4_610.103263673824688209 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.055 * 1e18, + interestRate: 0.045 * 1e18, interestRateUpdate: _startTime + 10 days }) ); _assertEMAs({ - debtColEma: 21_200_711.871301775167480082 * 1e18, - lupt0DebtEma: 137_258_193.699477886755027636 * 1e18, - debtEma: 46_044.230769230769252000 * 1e18, + debtColEma: 0, + lupt0DebtEma: 0, + debtEma: 0, depositEma: 109_999.904632568359400000 * 1e18 }); @@ -123,25 +123,25 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { _assertPool( PoolParams({ - htp: 461.177183352194672960 * 1e18, + htp: 461.043482411861952490 * 1e18, lup: 2_981.007422784467321543 * 1e18, - poolSize: 110_064.287293030035050000 * 1e18, + poolSize: 110_051.099851162112050000 * 1e18, pledgedCollateral: 100 * 1e18, - encumberedCollateral: 15.470514425000097931 * 1e18, - poolDebt: 46_117.718335219467295955 * 1e18, - actualUtilization: 0.600105299829839683 * 1e18, + encumberedCollateral: 15.466029332500467905 * 1e18, + poolDebt: 46_104.348241186195248997 * 1e18, + actualUtilization: 0.332788778646025592 * 1e18, targetUtilization: 0.154458625018190226 * 1e18, - minDebtAmount: 4_611.771833521946729596 * 1e18, + minDebtAmount: 4_610.434824118619524900 * 1e18, loans: 1, maxBorrower: _borrower, - interestRate: 0.0605 * 1e18, - interestRateUpdate: _startTime + 10 days + 14 hours + interestRate: 0.045 * 1e18, + interestRateUpdate: _startTime + 10 days }) ); _assertEMAs({ - debtColEma: 21_200_711.871301775167480082 * 1e18, - lupt0DebtEma: 137_258_193.699477886755027636 * 1e18, - debtEma: 46_044.230769230769252000 * 1e18, + debtColEma: 2_313_024.841496349382919830 * 1e18, + lupt0DebtEma: 14_975_044.878354639842735067 * 1e18, + debtEma: 25_533.857684197937318785 * 1e18, depositEma: 76_726.919062848880206510 * 1e18 }); @@ -154,7 +154,7 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { from: _borrower, borrower: _borrower, amountToRepay: 46_200 * 1e18, - amountRepaid: 46_117.718335219467295955 * 1e18, + amountRepaid: 46_104.348241186195248997 * 1e18, collateralToPull: 0, newLup: MAX_PRICE }); @@ -163,24 +163,24 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { PoolParams({ htp: 0, lup: MAX_PRICE, - poolSize: 110_064.287293030035050000 * 1e18, + poolSize: 110_051.099851162112050000 * 1e18, pledgedCollateral: 100 * 1e18, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 0.600105299829839683 * 1e18, + actualUtilization: 0.332788778646025592 * 1e18, targetUtilization: 0.154458625018190226 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), - interestRate: 0.0495 * 1e18, + interestRate: 0.0405 * 1e18, interestRateUpdate: _startTime + 10 days + 14 hours }) ); _assertEMAs({ - debtColEma: 21_200_711.871301775167480082 * 1e18, - lupt0DebtEma: 137_258_193.699477886755027636 * 1e18, - debtEma: 46_044.230769230769252000 * 1e18, + debtColEma: 2_313_024.841496349382919830 * 1e18, + lupt0DebtEma: 14_975_044.878354639842735067 * 1e18, + debtEma: 25_533.857684197937318785 * 1e18, depositEma: 76_726.919062848880206510 * 1e18 }); } @@ -237,8 +237,8 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { pledgedCollateral: 1_500 * 1e18, encumberedCollateral: 9.927311124438159308 * 1e18, poolDebt: 996.030634410028283604 * 1e18, - actualUtilization: 0.996030634410028284 * 1e18, - targetUtilization: 0.006618207416292106 * 1e18, + actualUtilization: 0.525927743411473669 * 1e18, + targetUtilization: 0.006617716357476524 * 1e18, minDebtAmount: 99.603063441002828360 * 1e18, loans: 1, maxBorrower: _borrower, @@ -309,8 +309,8 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { pledgedCollateral: 10 * 1e18, encumberedCollateral: 8.324533534321699024 * 1e18, poolDebt: 5_005.150499094935086587 * 1e18, - actualUtilization: 0.500515049909493509 * 1e18, - targetUtilization: 0.832453353432169902 * 1e18, + actualUtilization: 0.250240384615384603 * 1e18, + targetUtilization: 0.832396338031799592 * 1e18, minDebtAmount: 500.515049909493508659 * 1e18, loans: 1, maxBorrower: _borrower, @@ -376,7 +376,7 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { encumberedCollateral: 0.000000006658700114 * 1e18, poolDebt: 0.000010023099759839 * 1e18, actualUtilization: 0.000000001002307157 * 1e18, - targetUtilization: 0.000665851626199244 * 1e18, + targetUtilization: 0.000665852030273875 * 1e18, minDebtAmount: 0.000001002309975984 * 1e18, loans: 1, maxBorrower: _borrower, @@ -653,9 +653,9 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { poolSize: 20_001.166301815699560000 * 1e18, pledgedCollateral: 100 * 1e18, encumberedCollateral: 3.094069767562214045 * 1e18, - poolDebt: 1012.343273629329809307 * 1e18, - actualUtilization: 0.050617187817622486 * 1e18, - targetUtilization: 0.030943722563486265 * 1e18, + poolDebt: 1_012.343273629329809307 * 1e18, + actualUtilization: 0.050048053058282770 * 1e18, + targetUtilization: 0.030592832642066762 * 1e18, minDebtAmount: 50.617163681466490465 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -664,9 +664,9 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { }) ); _assertEMAs({ - debtColEma: 10_235.360311264941798142 * 1e18, - lupt0DebtEma: 330_773.399686006553854142 * 1e18, - debtEma: 1_012.343273629329809307 * 1e18, + debtColEma: 8_636.472785378662688101 * 1e18, + lupt0DebtEma: 282_303.796004265917437005 * 1e18, + debtEma: 1_000.960583870227520994 * 1e18, depositEma: 19_999.990463256835940000 * 1e18 }); } @@ -800,8 +800,8 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { pledgedCollateral: 100 * 1e18, encumberedCollateral: 58.236654596124865142 * 1e18, poolDebt: 19_054.349122034189453676 * 1e18, - actualUtilization: 0.476358955196505217 * 1e18, - targetUtilization: 0.584010402015984926 * 1e18, + actualUtilization: 0.475456504053686315 * 1e18, + targetUtilization: 0.582873969285693044 * 1e18, minDebtAmount: 952.717456101709472684 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -810,9 +810,9 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { }) ); _assertEMAs({ - debtColEma: 3635_946.432113250913630238 * 1e18, - lupt0DebtEma: 6225_824.779082841691329479 * 1e18, - debtEma: 19_054.349122034189453676 * 1e18, + debtColEma: 3_126_403.148307075893092949 * 1e18, + lupt0DebtEma: 5_363_772.124081052431303092 * 1e18, + debtEma: 19_018.251093534322898890 * 1e18, depositEma: 39_999.980926513671880000 * 1e18 }); @@ -834,12 +834,12 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { PoolParams({ htp: 200.941998518054562716 * 1e18, lup: 327.188250324085203338 * 1e18, - poolSize: 40_045.121523671487080000 * 1e18, + poolSize: 40_045.119710562067080000 * 1e18, pledgedCollateral: 50_100 * 1e18, encumberedCollateral: 58.353196900686720280 * 1e18, poolDebt: 19_092.480394752519489737 * 1e18, - actualUtilization: 0.476094974846641824 * 1e18, - targetUtilization: 0.584010402015984926 * 1e18, + actualUtilization: 0.476094973986474284 * 1e18, + targetUtilization: 0.583872645876088990 * 1e18, minDebtAmount: 954.624019737625974487 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -848,9 +848,9 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { }) ); _assertEMAs({ - debtColEma: 3_635_946.432113250913630238 * 1e18, - lupt0DebtEma: 6_225_824.779082841691329479 * 1e18, - debtEma: 19_054.349122034189453676 * 1e18, + debtColEma: 3_565_623.757561586266590548 * 1e18, + lupt0DebtEma: 6_106_851.867005073649467074 * 1e18, + debtEma: 19_054.349087608426800461 * 1e18, depositEma: 40_022.159713346932216568 * 1e18 }); @@ -866,12 +866,12 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { PoolParams({ htp: 200.969526704670605713 * 1e18, lup: 327.188250324085203338 * 1e18, - poolSize: 40_047.420826509653000000 * 1e18, + poolSize: 40_047.419013400059920000 * 1e18, pledgedCollateral: 50_100 * 1e18, encumberedCollateral: 58.370797186283932430 * 1e18, poolDebt: 19_098.239001402275530018 * 1e18, - actualUtilization: 0.476604459561723992 * 1e18, - targetUtilization: 0.584213148132606714 * 1e18, // big col. deposit barely affects + actualUtilization: 0.476604475533389646 * 1e18, + targetUtilization: 0.584103777552299209 * 1e18, // big col. deposit barely affects minDebtAmount: 954.911950070113776501 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -880,10 +880,10 @@ contract ERC20PoolInterestRateTestAndEMAs is ERC20HelperContract { }) ); _assertEMAs({ - debtColEma: 3_637_620.071316321624676289 * 1e18, // big col. deposit barely affects - lupt0DebtEma: 6_226_528.935447105141859984 * 1e18, - debtEma: 19_082.947576572936979769 * 1e18, - depositEma: 40_039.381071090348363568 * 1e18 + debtColEma: 3_579_931.895052572545685505 * 1e18, // big col. deposit barely affects + lupt0DebtEma: 6_128_931.249262523887589290 * 1e18, + debtEma: 19_082.947567966496316465 * 1e18, + depositEma: 40_039.379711258283363568 * 1e18 }); } diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsArbTake.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsArbTake.t.sol index a9f03311a..7263f1277 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsArbTake.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsArbTake.t.sol @@ -229,7 +229,7 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract { amount: 1 * 1e18, amountAdded: 0.999876712328767123 * 1e18, index: _i9_52, - lpAward: 0.999873539225944871 * 1e18, + lpAward: 0.999873539529846322 * 1e18, newLup: 9.721295865031779605 * 1e18 }); @@ -237,11 +237,11 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract { index: _i9_91, lpBalance: 2_000 * 1e18, collateral: 0, - deposit: 2_010.436714496623126000 * 1e18, - exchangeRate: 1.005218357248311563 * 1e18 + deposit: 2_010.436713885571218000 * 1e18, + exchangeRate: 1.005218356942785609 * 1e18 }); _assertReserveAuction({ - reserves: 24.540805142364598539 * 1e18, + reserves: 24.540827358578637023 * 1e18, claimableReserves : 0, claimableReservesRemaining: 0, auctionPrice: 0, @@ -282,32 +282,32 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract { quoteTokenAmount: 14.503461444385064128 * 1e18, bondChange: 0.145034614443850641 * 1e18, isReward: true, - lpAwardTaker: 5.303234072524906823 * 1e18, - lpAwardKicker: 0.144281700983723506 * 1e18 + lpAwardTaker: 5.303234074136771189 * 1e18, + lpAwardKicker: 0.144281701027576470 * 1e18 }); _assertLenderLpBalance({ lender: _taker, index: _i9_91, - lpBalance: 5.303234072524906823 * 1e18, + lpBalance: 5.303234074136771189 * 1e18, depositTime: _startTime + 100 days + 6.5 hours }); _assertLenderLpBalance({ lender: _lender, index: _i9_91, - lpBalance: 2_000.144281700983723506 * 1e18, // rewarded with LP in bucket + lpBalance: 2_000.144281701027576470 * 1e18, // rewarded with LP in bucket depositTime: _startTime + 100 days + 6.5 hours }); _assertBucket({ index: _i9_91, - lpBalance: 2_005.447515773508630329 * 1e18, + lpBalance: 2_005.447515775164347659 * 1e18, collateral: 2 * 1e18, - deposit: 1_996.078287666681912514 * 1e18, - exchangeRate: 1.005218357248311563 * 1e18 + deposit: 1_996.078287055630004514 * 1e18, + exchangeRate: 1.005218356942785609 * 1e18 }); // reserves should remain the same after arb take _assertReserveAuction({ - reserves: 25.925343323521952869 * 1e18, + reserves: 25.925365539735991347 * 1e18, claimableReserves : 0, claimableReservesRemaining: 0, auctionPrice: 0, @@ -423,7 +423,7 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract { exchangeRate: 1 * 1e18 }); _assertReserveAuction({ - reserves: 26.111530884129153303 * 1e18, + reserves: 26.111547973458754923 * 1e18, claimableReserves : 0, claimableReservesRemaining: 0, auctionPrice: 0, @@ -615,7 +615,7 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract { index: _i10016, lpBalance: 3_562.597355112798042 * 1e18, // LP balance in arbed bucket increased with LP awarded for arb taker collateral: 0.257950403803869741 * 1e18, // arbed collateral added to the arbed bucket - deposit: 978.836725452666849367 * 1e18, // quote token amount is diminished in arbed bucket + deposit: 978.836725452666849368 * 1e18, // quote token amount is diminished in arbed bucket exchangeRate: 1 * 1e18 }); _assertAuction( diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsDepositTake.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsDepositTake.t.sol index f8bd86971..6b35a4ef7 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsDepositTake.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsDepositTake.t.sol @@ -229,7 +229,7 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract { amount: 1 * 1e18, amountAdded: 0.999876712328767123 * 1e18, index: _i9_52, - lpAward: 0.999873479213875107 * 1e18, + lpAward: 0.999873479995558788 * 1e18, newLup: 9.721295865031779605 * 1e18 }); @@ -237,12 +237,12 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract { index: _i9_91, lpBalance: 2_000 * 1e18, collateral: 0, - deposit: 2_026.352753018872710000 * 1e18, - exchangeRate: 1.013176376509436355 * 1e18 + deposit: 2_026.352751434705402000 * 1e18, + exchangeRate: 1.013176375717352701 * 1e18 }); _assertReserveAuction({ - reserves: 49.824792135962495179 * 1e18, - claimableReserves : 8.392655686771763037 * 1e18, + reserves: 49.824849391649864823 * 1e18, + claimableReserves : 8.392712942459132681 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 @@ -283,7 +283,7 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract { bondChange: 0.198343696868718241 * 1e18, isReward: true, lpAwardTaker: 0, - lpAwardKicker: 0.195764233619466887 * 1e18 + lpAwardKicker: 0.195764233772511957 * 1e18 }); _assertLenderLpBalance({ @@ -295,20 +295,20 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract { _assertLenderLpBalance({ lender: _lender, index: _i9_91, - lpBalance: 2_000.195764233619466887 * 1e18, + lpBalance: 2_000.195764233772511957 * 1e18, depositTime: _startTime + 250 days + 6.5 hours }); _assertBucket({ index: _i9_91, - lpBalance: 2_000.195764233619466887 * 1e18, + lpBalance: 2_000.195764233772511957 * 1e18, collateral: 2 * 1e18, - deposit: 2_006.716727028869604094 * 1e18, - exchangeRate: 1.013176376509436355 * 1e18 + deposit: 2_006.716725444702296094 * 1e18, + exchangeRate: 1.013176375717352701 * 1e18 }); // reserves should remain the same after deposit take _assertReserveAuction({ - reserves: 51.238074032610772537 * 1e18, - claimableReserves : 9.897051303886814538 * 1e18, + reserves: 51.238131288298142182 * 1e18, + claimableReserves : 9.897108559574184183 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 @@ -426,12 +426,12 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract { index: _i1505_26, lpBalance: 25_000 * 1e18, collateral: 0.014351542794629452 * 1e18, - deposit: 24_978.397143183672680231 * 1e18, + deposit: 24_978.397143183672680230 * 1e18, exchangeRate: 1 * 1e18 }); _assertReserveAuction({ - reserves: 51.428137480706929986 * 1e18, - claimableReserves : 10.097268213810519088 * 1e18, + reserves: 51.428181523373734113 * 1e18, + claimableReserves : 10.097312256477323215 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKick.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKick.t.sol index 83a526a71..f3c3acd56 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKick.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKick.t.sol @@ -183,8 +183,8 @@ contract ERC20PoolLiquidationsKickTest is ERC20HelperContract { pledgedCollateral: 1_002 * 1e18, encumberedCollateral: 835.035237319063220561 * 1e18, poolDebt: 8_117.624599705640061721 * 1e18, - actualUtilization: 0.111200336982269042 * 1e18, - targetUtilization: 0.833449668459897038 * 1e18, + actualUtilization: 0.109684131322444679 * 1e18, + targetUtilization: 0.822075127292417292 * 1e18, minDebtAmount: 811.762459970564006172 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -723,8 +723,8 @@ contract ERC20PoolLiquidationsKickTest is ERC20HelperContract { pledgedCollateral: 1_002 * 1e18, encumberedCollateral: 1_028.290450922889736704 * 1e18, poolDebt: 9_996.315708608352095626 * 1e18, - actualUtilization: 0.555338663776728288 * 1e18, - targetUtilization: 1.026216314846201384 * 1e18, + actualUtilization: 0.541033613782051282 * 1e18, + targetUtilization: 0.999781133426980224 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -740,7 +740,7 @@ contract ERC20PoolLiquidationsKickTest is ERC20HelperContract { from: _lender1, amount: 1 * 1e18, index: _i9_91, - lpAward: 0.993688275531219296 * 1e18, + lpAward: 0.993688287401017551 * 1e18, newLup: 9.721295865031779605 * 1e18 }); @@ -748,12 +748,12 @@ contract ERC20PoolLiquidationsKickTest is ERC20HelperContract { PoolParams({ htp: 0, lup: 9.721295865031779605 * 1e18, - poolSize: 73_115.811578712752097363 * 1e18, + poolSize: 73_115.810705342225439101 * 1e18, pledgedCollateral: 1_002 * 1e18, encumberedCollateral: 1_028.364405977643667984 * 1e18, poolDebt: 9_997.034647576329686631 * 1e18, - actualUtilization: 0.737099854301327286 * 1e18, - targetUtilization: 1.026218700245164092 * 1e18, + actualUtilization: 0.100661311571554831 * 1e18, + targetUtilization: 0.999781133426980224 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKickWithDeposit.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKickWithDeposit.t.sol index 3930c3189..1aac9eb10 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKickWithDeposit.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsKickWithDeposit.t.sol @@ -1240,12 +1240,12 @@ contract ERC20PoolLiquidationsKickWithDepositTest is ERC20HelperContract { pledgedCollateral: 3_978.965725315792902720 * 1e18, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 0.804376804158714743 * 1e18, - targetUtilization: 203_119_829.249967715714383718 * 1e18, + actualUtilization: 0, + targetUtilization: 1 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), - interestRate: 0.055 * 1e18, + interestRate: 0.045 * 1e18, interestRateUpdate: _startTime + 80 hours }) ); diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsMisc.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsMisc.t.sol index 21bc32f71..4c36ed68a 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsMisc.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsMisc.t.sol @@ -213,8 +213,8 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { index: _i9_72, lpBalance: 8_007.361474606956967925 * 1e18, collateral: 0, - deposit: 8_008.357922841256875798 * 1e18, - exchangeRate: 1.000124441520151158 * 1e18 + deposit: 8_008.356713096000609696 * 1e18, + exchangeRate: 1.000124290441014778 * 1e18 }); _assertAuction( AuctionParams({ @@ -317,12 +317,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 7.989580407145861718 * 1e18, lup: 9.721295865031779605 * 1e18, - poolSize: 63_008.830844290339398722 * 1e18, + poolSize: 63_008.829558890303235305 * 1e18, pledgedCollateral: 1_001.742368450520005091 * 1e18, encumberedCollateral: 821.863722498661263922 * 1e18, poolDebt: 7_989.580407145861717463 * 1e18, - actualUtilization: 0.131818845026319233 * 1e18, - targetUtilization: 0.822394462551326847 * 1e18, + actualUtilization: 0.121389299635877703 * 1e18, + targetUtilization: 0.822758145478171949 * 1e18, minDebtAmount: 798.958040714586171746 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -333,7 +333,7 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { _removeLiquidity({ from: _lender, - amount: 8_008.370021911110254226 * 1e18, + amount: 8_008.368802555852473042 * 1e18, index: _i9_72, newLup: 9.624807173121239337 * 1e18, lpRedeem: 8_007.361474606956967925 * 1e18 @@ -349,18 +349,18 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { _removeLiquidity({ from: _lender, - amount: 25_000.037756489769875000 * 1e18, + amount: 25_000.037740139097750000 * 1e18, index: _i9_62, newLup: 9.529276179422528643 * 1e18, - lpRedeem: 24_999.999986356481162701 * 1e18 + lpRedeem: 25_000.000000000000000000 * 1e18 }); _assertBucket({ index: _i9_62, - lpBalance: 0.000013643518837299 * 1e18, + lpBalance: 0.000000000000000000 * 1e18, collateral: 0, - deposit: 0.000013643539450000 * 1e18, - exchangeRate: 1.000001510805331514 * 1e18 + deposit: 0.000000000000000000 * 1e18, + exchangeRate: 1.000000000000000000 * 1e18 }); _removeLiquidity({ @@ -368,15 +368,15 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { amount: 22_000 * 1e18, index: _i9_52, newLup: 9.529276179422528643 * 1e18, - lpRedeem: 21_999.966762332903438685 * 1e18 + lpRedeem: 21_999.966788727729901403 * 1e18 }); _assertBucket({ index: _i9_52, - lpBalance: 8_000.033237667096561315 * 1e18, + lpBalance: 8_000.033211272270098597 * 1e18, collateral: 0, - deposit: 8_000.045324159971190000 * 1e18, - exchangeRate: 1.000001510805332373 * 1e18 + deposit: 8_000.045288166917300000 * 1e18, + exchangeRate: 1.000001509605563910 * 1e18 }); _assertRemoveAllLiquidityLupBelowHtpRevert({ @@ -390,12 +390,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 7.989580407145861718 * 1e18, lup: 9.529276179422528643 * 1e18, - poolSize: 8_000.423065889459267791 * 1e18, + poolSize: 8_000.423016195353009887 * 1e18, pledgedCollateral: 1_001.742368450520005091 * 1e18, encumberedCollateral: 838.521600516187410670 * 1e18, poolDebt: 7_990.503913730158190391 * 1e18, - actualUtilization: 0.131818845026319233 * 1e18, - targetUtilization: 0.822394462551326847 * 1e18, + actualUtilization: 0.121389299635877703 * 1e18, + targetUtilization: 0.822758145478171949 * 1e18, minDebtAmount: 799.050391373015819039 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -418,12 +418,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 7.990503913730158191 * 1e18, lup: 9.529276179422528643 * 1e18, - poolSize: 8_001.214422208222835222 * 1e18, + poolSize: 8_001.213845441074207570 * 1e18, pledgedCollateral: 1_001.742368450520005091 * 1e18, encumberedCollateral: 838.521600516187410670 * 1e18, poolDebt: 7_990.503913730158190391 * 1e18, - actualUtilization: 0.390940447746469293 * 1e18, - targetUtilization: 0.825329194875392075 * 1e18, + actualUtilization: 0.383638005890774049 * 1e18, + targetUtilization: 0.829403289225492236 * 1e18, minDebtAmount: 799.050391373015819039 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -450,12 +450,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 0, lup: 0.000000099836282890 * 1e18, - poolSize: 8_002.338364349478802466 * 1e18, + poolSize: 8_002.290256803028931336 * 1e18, pledgedCollateral: 1_001.742368450520005091 * 1e18, encumberedCollateral: 81_714_595_700.439346767851204401 * 1e18, poolDebt: 8_158.081492591040321202 * 1e18, - actualUtilization: 0.998661389645009827 * 1e18, - targetUtilization: 0.838521600515025555 * 1e18, + actualUtilization: 0.998661461633472237 * 1e18, + targetUtilization: 0.838521600515840801 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -510,12 +510,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 0, lup: 0.000000099836282890 * 1e18, - poolSize: 8_002.705599795829394966 * 1e18, + poolSize: 8_002.657492360039013361 * 1e18, pledgedCollateral: 1.742368450520005091 * 1e18, encumberedCollateral: 82_124_923_660.837160770168974387 * 1e18, poolDebt: 8_199.047110922993196875 * 1e18, - actualUtilization: 0.999255137826161539 * 1e18, - targetUtilization: 0.912833017390738664 * 1e18, + actualUtilization: 0.998661461633472237 * 1e18, + targetUtilization: 0.838521600515840801 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -548,12 +548,12 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { PoolParams({ htp: 0, lup: MAX_PRICE, - poolSize: 470.466606572217578962 * 1e18, + poolSize: 470.467842278147479905 * 1e18, pledgedCollateral: 1.742368450520005091 * 1e18, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 0.999255137826161539 * 1e18, - targetUtilization: 0.912833017390738664 * 1e18, + actualUtilization: 0.998661461633472237 * 1e18, + targetUtilization: 0.838521600515840801 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -592,10 +592,10 @@ contract ERC20PoolLiquidationsMiscTest is ERC20HelperContract { // TODO: review, strange values _assertBucket({ index: _i9_52, - lpBalance: 7_920.016955825447655160 * 1e18, + lpBalance: 7_920.016453607093220646 * 1e18, collateral: 0, - deposit: 470.466606572217578831 * 1e18, - exchangeRate: 0.059402222141225726 * 1e18 + deposit: 470.467842278147479912 * 1e18, + exchangeRate: 0.059402381931148331 * 1e18 }); } } diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsSettle.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsSettle.t.sol index 962473981..265f4ee26 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsSettle.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsSettle.t.sol @@ -288,22 +288,22 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { index: _i9_91, lpBalance: 2_000 * 1e18, collateral: 0, - deposit: 2_012.736630048845584000 * 1e18, - exchangeRate: 1.006368315024422792 * 1e18 + deposit: 2_012.736560735960384000 * 1e18, + exchangeRate: 1.006368280367980192 * 1e18 }); _assertBucket({ index: _i9_81, lpBalance: 5_000 * 1e18, collateral: 0, - deposit: 5_031.841575122113960000 * 1e18, - exchangeRate: 1.006368315024422792 * 1e18 + deposit: 5_031.841401839900960000 * 1e18, + exchangeRate: 1.006368280367980192 * 1e18 }); _assertBucket({ index: _i9_72, lpBalance: 11_000 * 1e18, collateral: 0, - deposit: 11_070.051465268650712000 * 1e18, - exchangeRate: 1.006368315024422792 * 1e18 + deposit: 11_070.051084047782112000 * 1e18, + exchangeRate: 1.006368280367980192 * 1e18 }); _assertBucket({ index: _i9_62, @@ -327,8 +327,8 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { index: _i9_91, lpBalance: 2_000 * 1e18, collateral: 0, - deposit: 2_012.736630048845584000 * 1e18, - exchangeRate: 1.006368315024422792 * 1e18 + deposit: 2_012.736560735960384000 * 1e18, + exchangeRate: 1.006368280367980192 * 1e18 }); _settle({ @@ -379,7 +379,7 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { index: _i9_72, lpBalance: 11_000 * 1e18, collateral: 0, - deposit: 8_807.556879218687263263 * 1e18, + deposit: 8_807.556879218687263265 * 1e18, exchangeRate: 0.800686989019880660 * 1e18 }); _assertBucket({ @@ -393,16 +393,16 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { PoolParams({ htp: 9.771304290202671377 * 1e18, lup: 9.721295865031779605 * 1e18, - poolSize: 63_807.556879218687263263 * 1e18, + poolSize: 63_807.556879218687263265 * 1e18, pledgedCollateral: 2 * 1e18, encumberedCollateral: 2.010288427770370775 * 1e18, poolDebt: 19.542608580405342754 * 1e18, - actualUtilization: 0.993531222480240308 * 1e18, - targetUtilization: 2.940996143103583563 * 1e18, + actualUtilization: 0.593847771807726236 * 1e18, + targetUtilization: 0.999790809254532429 * 1e18, minDebtAmount: 1.954260858040534275 * 1e18, loans: 1, maxBorrower: address(_borrower), - interestRate: 0.0495 * 1e18, + interestRate: 0.0405 * 1e18, interestRateUpdate: _startTime + 83 hours + 100 days }) ); @@ -566,23 +566,23 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { _assertBucket({ index: _i9_91, lpBalance: 2_000 * 1e18, - collateral: 202.986535499495858324 * 1e18, + collateral: 202.986484470302055714 * 1e18, deposit: 0, - exchangeRate: 1.006527496638583021 * 1e18 + exchangeRate: 1.006527243605609345 * 1e18 }); _assertBucket({ index: _i9_81, lpBalance: 5_000 * 1e18, - collateral: 512.553688794695752468 * 1e18, + collateral: 512.553559942792076265 * 1e18, deposit: 0, - exchangeRate: 1.006527496638583021 * 1e18 + exchangeRate: 1.006527243605609345 * 1e18 }); _assertBucket({ index: _i9_72, lpBalance: 11_000 * 1e18, - collateral: 284.459775705808389208 * 1e18, + collateral: 284.459955586905868021 * 1e18, deposit: 8_290.291604705064327150 * 1e18, - exchangeRate: 1.005055386003800627 * 1e18 + exchangeRate: 1.005055544974470547 * 1e18 }); _assertBucket({ index: _i9_62, @@ -719,14 +719,14 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { from: _lender1, amount: 100 * 1e18, index: _i9_91, - lpAward: 99.367198377636894880 * 1e18, + lpAward: 99.367201799558744045 * 1e18, newLup: 9.721295865031779605 * 1e18 }); _assertLenderLpBalance({ lender: _lender1, index: _i9_91, - lpBalance: 99.367198377636894880 * 1e18, + lpBalance: 99.367201799558744045 * 1e18, depositTime: _startTime + 100 days + 10 hours }); @@ -752,6 +752,11 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { assertTrue(block.timestamp - kickTime < 72 hours); // assert auction was kicked less than 72 hours ago + // LP forfeited when forgive bad debt should be reflected in BucketBankruptcy event + vm.expectEmit(true, true, false, true); + emit BucketBankruptcy(_i9_91, 2_099.367201799558744045 * 1e18); + vm.expectEmit(true, true, false, true); + emit BucketBankruptcy(_i9_81, 5_000 * 1e18); _settle({ from: _lender, borrower: _borrower2, @@ -867,8 +872,8 @@ contract ERC20PoolLiquidationsSettleTest is ERC20HelperContract { index: _i9_72, lpBalance: 11_000 * 1e18, collateral: 0 * 1e18, - deposit: 9_036.878038705612120074 * 1e18, - exchangeRate: 0.821534367155055647 * 1e18 + deposit: 9_036.878037285796943111 * 1e18, + exchangeRate: 0.821534367025981540 * 1e18 }); _pool.moveQuoteToken(10000000000 * 1e18, _i9_72, _i9_91, type(uint256).max); @@ -950,7 +955,7 @@ contract ERC20PoolLiquidationsSettleRegressionTest is ERC20HelperContract { assertEq(collateral, 0); assertEq(deposit, 2); (uint256 borrowerDebt, uint256 borrowerCollateral, ) = _pool.borrowerInfo(actor1); - assertEq(borrowerDebt, 987909.179343464530923023 * 1e18); + assertEq(borrowerDebt, 985_735.245058880968054979 * 1e18); assertEq(borrowerCollateral, 10066231386838.450530455239517417 * 1e18); changePrank(actor8); @@ -964,7 +969,7 @@ contract ERC20PoolLiquidationsSettleRegressionTest is ERC20HelperContract { assertEq(collateral, 0); // no collateral added in bucket 2571 assertEq(deposit, 0); // entire deposit from bucket 2571 used to settle (borrowerDebt, borrowerCollateral, ) = _pool.borrowerInfo(actor1); - assertEq(borrowerDebt, 987909.179343464530923022 * 1e18); // decreased with 1 + assertEq(borrowerDebt, 985_735.245058880968054978 * 1e18); // decreased with 1 assertEq(borrowerCollateral, 10066231386838.450530455239517417 * 1e18); // same as before settle } @@ -996,7 +1001,7 @@ contract ERC20PoolLiquidationsSettleRegressionTest is ERC20HelperContract { _kick({ from: actor4, borrower: actor2, - debt: 58_824_226_156.322179644993506974 * 1e18, + debt: 58_679_160_247.182050965227801655 * 1e18, collateral: 21_009_851.171858165566322122 * 1e18, bond: 580_263_636.560514719062821277 * 1e18, transferAmount: 580_263_636.560514719062821277 * 1e18 @@ -1007,7 +1012,7 @@ contract ERC20PoolLiquidationsSettleRegressionTest is ERC20HelperContract { ERC20Pool(address(_pool)).updateInterest(); _kickReserveAuction({ from: actor1, - remainingReserves: 785_271_398.552730383160590325 * 1e18, + remainingReserves: 642_374_224.754246627157382301 * 1e18, price: 1_000_000_000 * 1e18, epoch: 1 }); @@ -1031,17 +1036,17 @@ contract ERC20PoolLiquidationsSettleRegressionTest is ERC20HelperContract { ERC20Pool(address(_pool)).updateInterest(); (uint256 borrowerDebt, , ) = _poolUtils.borrowerInfo(address(_pool), actor2); - assertEq(borrowerDebt, 60_623_994_637.102713529810847735 * 1e18); + assertEq(borrowerDebt, 60_144_029_463.415046012797744619 * 1e18); (uint256 reserves, , , ,) = _poolUtils.poolReservesInfo(address(_pool)); - assertEq(reserves, 294_122_188.473918671419077285 * 1e18); + assertEq(reserves, 467_743_845.048670767464288715 * 1e18); // settle auction with reserves _settle({ from: actor6, borrower: actor2, maxDepth: 2, - settledDebt: 57_234_480_301.052435683555399515 * 1e18 + settledDebt: 57_093_334_850.248360626382636508 * 1e18 }); (reserves, , , ,) = _poolUtils.poolReservesInfo(address(_pool)); diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsTake.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsTake.t.sol index 1a10ed2fb..074c5d833 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsTake.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolLiquidationsTake.t.sol @@ -314,8 +314,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { pledgedCollateral: 2_002.000000000000000000 * 1e18, encumberedCollateral: 1_966.791200431324241706 * 1e18, poolDebt: 19_119.759164133922414841 * 1e18, - actualUtilization: 0.230343095389734878 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.225749991311399444 * 1e18, + targetUtilization: 0.963953858271529038 * 1e18, minDebtAmount: 1_911.975916413392241484 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -352,9 +352,9 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { from: _lender, borrower: _borrower2, maxCollateral: 1_001 * 1e18, - bondChange: 3_598.602058071496018124* 1e18, + bondChange: 3_598.602058071496018124 * 1e18, givenAmount: 12_005.655124053999200000 * 1e18, - collateralTaken: 1000.0 * 1e18, + collateralTaken: 1_000 * 1e18, isReward: true }); @@ -388,12 +388,12 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { PoolParams({ htp: 9.155043929439064212 * 1e18, lup: 9.917184843435912074 * 1e18, - poolSize: 83_220.780619576281629747 * 1e18, + poolSize: 83_220.780269640882398489 * 1e18, pledgedCollateral: 1_002.0 * 1e18, encumberedCollateral: 1_150.422689356386608344 * 1e18, poolDebt: 11_408.954458429937838015 * 1e18, - actualUtilization: 0.284378049198767977 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.175461408132427911 * 1e18, + targetUtilization: 0.962794543732489691 * 1e18, minDebtAmount: 1_140.895445842993783802 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -438,12 +438,12 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { PoolParams({ htp: 9.155043929439064212 * 1e18, lup: 9.917184843435912074 * 1e18, - poolSize: 83_220.780619576281629747 * 1e18, + poolSize: 83_220.780269640882398489 * 1e18, pledgedCollateral: 2_002.0 * 1e18, encumberedCollateral: 1_150.422689356386608344 * 1e18, poolDebt: 11_408.954458429937838015 * 1e18, - actualUtilization: 0.284378049198767977 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.175461408132427911 * 1e18, + targetUtilization: 0.962794543732489691 * 1e18, minDebtAmount: 570.447722921496891901 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -591,8 +591,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { pledgedCollateral: 2_002.000000000000000000 * 1e18, encumberedCollateral: 1_966.779974486190376300 * 1e18, poolDebt: 19_119.650033399911495436 * 1e18, - actualUtilization: 0.230343095389734878 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.225749991311399444 * 1e18, + targetUtilization: 0.963953858271529038 * 1e18, minDebtAmount: 1_911.965003339991149544 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -799,8 +799,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { pledgedCollateral: 2_002.000000000000000000 * 1e18, encumberedCollateral: 1_966.779974486190376300 * 1e18, poolDebt: 19_119.650033399911495436 * 1e18, - actualUtilization: 0.230343095389734878 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.225749991311399444 * 1e18, + targetUtilization: 0.963953858271529038 * 1e18, minDebtAmount: 1_911.965003339991149544 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -836,10 +836,10 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { _take({ from: _lender, borrower: _borrower2, - maxCollateral: 577.0 * 1e18, + maxCollateral: 577 * 1e18, bondChange: 4_445.845186520884185062 * 1e18, givenAmount: 14_963.715748248473943872 * 1e18, - collateralTaken: 577.000000000000000000 * 1e18, + collateralTaken: 577 * 1e18, isReward: true }); @@ -961,8 +961,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { pledgedCollateral: 1_002 * 1e18, encumberedCollateral: 1_025.107650389722106875 * 1e18, poolDebt: 9_965.374762946048672276 * 1e18, - actualUtilization: 0.553626243304705638 * 1e18, - targetUtilization: 1.023051673698045482 * 1e18, + actualUtilization: 0.539365344551282052 * 1e18, + targetUtilization: 0.996698234880015451 * 1e18, minDebtAmount: 996.537476294604867228 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -1009,12 +1009,12 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { PoolParams({ htp: 9.767239336407496599 * 1e18, lup: 9.721295865031779605 * 1e18, - poolSize: 73_113.913540853182360000 * 1e18, + poolSize: 73_113.913417169507608000 * 1e18, pledgedCollateral: 992.0 * 1e18, encumberedCollateral: 925.265940856763249327 * 1e18, poolDebt: 8_994.783964905591719091 * 1e18, - actualUtilization: 0.581968058078338251 * 1e18, - targetUtilization: 1.023051673698045482 * 1e18, + actualUtilization: 0.539426554958980321 * 1e18, + targetUtilization: 0.996698499658312393 * 1e18, minDebtAmount: 449.739198245279585955 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -1187,8 +1187,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { pledgedCollateral: 2_002.000000000000000000 * 1e18, encumberedCollateral: 1_966.779974486190376300 * 1e18, poolDebt: 19_119.650033399911495436 * 1e18, - actualUtilization: 0.230343095389734878 * 1e18, - targetUtilization: 0.984033535061047652 * 1e18, + actualUtilization: 0.225749991311399444 * 1e18, + targetUtilization: 0.963953858271529038 * 1e18, minDebtAmount: 1_911.965003339991149544 * 1e18, loans: 1, maxBorrower: address(_borrower), @@ -1461,8 +1461,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { }); // reserves should increase after take action _assertReserveAuction({ - reserves: 851.124981254581185156 * 1e18, - claimableReserves : 797.714616029940013190 * 1e18, + reserves: 851.125605070547985156 * 1e18, + claimableReserves : 797.715239845906813190 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 @@ -1509,8 +1509,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { }); // reserves should increase after take action _assertReserveAuction({ - reserves: 851.124981254581184803 * 1e18, - claimableReserves : 800.882859687599489602 * 1e18, + reserves: 851.125605070547984803 * 1e18, + claimableReserves : 800.883483503566289602 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 @@ -1530,8 +1530,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { index: 3_696, lpBalance: 2_000 * 1e18, collateral: 0, - deposit: 2_012.736630048845584000 * 1e18, - exchangeRate: 1.006368315024422792 * 1e18 + deposit: 2_012.736560735960384000 * 1e18, + exchangeRate: 1.006368280367980192 * 1e18 }); _settle({ @@ -1599,7 +1599,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { index: _i9_72, lpBalance: 11_000 * 1e18, collateral: 0, - deposit: 8_936.865619773958012093 * 1e18, + deposit: 8_936.865619773958012095 * 1e18, exchangeRate: 0.812442329070359819 * 1e18 }); _assertLenderLpBalance({ @@ -1638,8 +1638,8 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { vm.revertTo(postTakeSnapshot); _assertReserveAuction({ - reserves: 851.124981254581184803 * 1e18, - claimableReserves : 800.882859687599489602 * 1e18, + reserves: 851.125605070547984803 * 1e18, + claimableReserves : 800.883483503566289602 * 1e18, claimableReservesRemaining: 0, auctionPrice: 0, timeRemaining: 0 @@ -1649,7 +1649,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { from: _lender, borrower: _borrower2, maxDepth: 0, - settledDebt: 839.502103169454585516 * 1e18 + settledDebt: 839.502718466652592026 * 1e18 }); _assertReserveAuction({ reserves: 0, @@ -1664,7 +1664,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { from: _lender, borrower: _borrower2, maxDepth: 1, - settledDebt: 1_985.250898829861493554 * 1e18 + settledDebt: 1_985.250830463506159498 * 1e18 }); _assertAuction( @@ -1678,14 +1678,14 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { kickMomp: 9.818751856078723036 * 1e18, totalBondEscrowed: 105.065056948053351817 * 1e18, auctionPrice: 0.653111452826113536 * 1e18, - debtInAuction: 7_165.027420616806659906 * 1e18, + debtInAuction: 7_165.026866113725059905 * 1e18, thresholdPrice: 0, neutralPrice: 10.449783245217816340 * 1e18 }) ); _assertBorrower({ borrower: _borrower2, - borrowerDebt: 7_165.027420616806659906 * 1e18, + borrowerDebt: 7_165.026866113725059905 * 1e18, borrowerCollateral: 0, borrowert0Np: 10.307611531622595991 * 1e18, borrowerCollateralization: 0 @@ -1701,7 +1701,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { from: _lender, borrower: _borrower2, maxDepth: 5, - settledDebt: 7_067.182518844961267852 * 1e18 + settledDebt: 7_067.181971914118595398 * 1e18 }); _assertAuction( @@ -1878,7 +1878,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { }); } - function testTakeAfterSettleReverts() external { + function testTakeAfterSettleReverts() external tearDown { // Borrower draws debt _borrow({ from: _borrower2, @@ -1905,7 +1905,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { borrower: _borrower2, maxCollateral: 1_000 * 1e18, bondChange: 6.531114528261135360 * 1e18, - givenAmount: 653.111452826113536000 * 1e18, + givenAmount: 653.1114528261135360 * 1e18, collateralTaken: 1_000 * 1e18, isReward: true }); @@ -1915,7 +1915,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { from: _lender, borrower: _borrower2, maxDepth: 1, - settledDebt: 2_824.753001999316079070 * 1e18 + settledDebt: 2_824.753548930158751524 * 1e18 }); // Borrower draws more debt @@ -2085,7 +2085,7 @@ contract ERC20PoolLiquidationsTakeTest is ERC20HelperContract { (uint256 reservesAfterTake, , , , ) = _poolUtils.poolReservesInfo(address(_pool)); // reserves should only increase by 7% of the borrower debt on first take and settle auction - assertEq(reservesAfterTake, reservesBeforeTake + Maths.wmul(borrowerDebt, 0.07 * 1e18)); + assertEq(reservesAfterTake, reservesBeforeTake + Maths.floorWmul(borrowerDebt, 0.07 * 1e18)); } } diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolPurchaseQuote.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolPurchaseQuote.t.sol index 648f13482..ebdef9e4a 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolPurchaseQuote.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolPurchaseQuote.t.sol @@ -236,7 +236,7 @@ contract ERC20PoolPurchaseQuoteTokenTest is ERC20HelperContract { // bidder purchases all quote from the highest bucket uint256 amountToPurchase = 10_100 * 1e18; assertGt(_quote.balanceOf(address(_pool)), amountToPurchase); - uint256 amountWithInterest = 10_001.282942146414260000 * 1e18; + uint256 amountWithInterest = 10_001.272716138919720000 * 1e18; // adding extra collateral to account for interest accumulation uint256 collateralToPurchaseWith = Maths.wmul(Maths.wdiv(amountToPurchase, p2550), 1.01 * 1e18); assertEq(collateralToPurchaseWith, 3.388032491631335842 * 1e18); @@ -256,17 +256,17 @@ contract ERC20PoolPurchaseQuoteTokenTest is ERC20HelperContract { amount: amountWithInterest, index: 2550, newLup: _priceAt(2552), - lpRedeem: 10_000.353515519837848818 * 1e18 + lpRedeem: 10_000.348352446860839169 * 1e18 }); // bidder withdraws unused collateral - uint256 expectedCollateral = 0.066448947605530167 * 1e18; + uint256 expectedCollateral = 0.066450628927305146 * 1e18; _removeAllCollateral({ from: _bidder, amount: expectedCollateral, index: 2550, - lpRedeem: 200.052013519410424905 * 1e18 + lpRedeem: 200.057176592387434554 * 1e18 }); _assertLenderLpBalance({ @@ -279,7 +279,7 @@ contract ERC20PoolPurchaseQuoteTokenTest is ERC20HelperContract { skip(7200); // lender exchanges their LP for collateral - expectedCollateral = 1.992950126415483406 * 1e18; + expectedCollateral = 1.992949117622418417 * 1e18; _removeAllCollateral({ from: _lender, @@ -298,13 +298,13 @@ contract ERC20PoolPurchaseQuoteTokenTest is ERC20HelperContract { skip(3600); // lender1 exchanges their LP for collateral - expectedCollateral = 1.328633417610322269 * 1e18; + expectedCollateral = 1.328632745081612279 * 1e18; _removeAllCollateral({ from: _lender1, amount: expectedCollateral, index: 2550, - lpRedeem: 3_999.999999999999999063 * 1e18 + lpRedeem: 3_999.999999999999999139 * 1e18 }); _assertLenderLpBalance({ diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolQuoteToken.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolQuoteToken.t.sol index a5f99db9b..013736d79 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolQuoteToken.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolQuoteToken.t.sol @@ -734,7 +734,7 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { amount: withdrawal1, index: 1606, newLup: _priceAt(1663), - lpRedeem: 1_699.988264063119375503 * 1e18 + lpRedeem: 1_699.989134088091859893 * 1e18 }); // lender removes all quote token, including interest, from the bucket @@ -742,13 +742,13 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { assertGt(_priceAt(1606), _htp()); - uint256 expectedWithdrawal2 = 1_700.147864111729705749 * 1e18; + uint256 expectedWithdrawal2 = 1_700.138879728085771159 * 1e18; _removeAllLiquidity({ from: _lender, amount: expectedWithdrawal2, index: 1606, newLup: _priceAt(1663), - lpRedeem: 1_700.011735936880624497 * 1e18 + lpRedeem: 1_700.010865911908140107 * 1e18 }); assertEq(_quote.balanceOf(_lender), lenderBalanceBefore + withdrawal1 + expectedWithdrawal2); @@ -770,8 +770,8 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { index: 1663, lpBalance: 3_400 * 1e18, collateral: 0, - deposit: 3_400.272254470191528600 * 1e18, - exchangeRate: 1.000080074844173979 * 1e18 + deposit: 3_400.256025995910604600 * 1e18, + exchangeRate: 1.000075301763503119 * 1e18 }); _assertLenderLpBalance({ lender: _lender, @@ -1155,7 +1155,7 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { from: _lender1, amount: 1_000 * 1e18, index: 2873, - lpAward: 999.958129650486586454 * 1e18, + lpAward: 999.958177826584067212 * 1e18, newLup: 601.252968524772188572 * 1e18 }); @@ -1168,7 +1168,7 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { amountMoved: 2_499.691780821917807500 * 1e18, fromIndex: lupIndex, toIndex: 2954, - lpRedeemFrom: 2_499.815331532038898922 * 1e18, + lpRedeemFrom: 2_499.816688122962822235 * 1e18, lpAwardTo: 2_499.691780821917807500 * 1e18, newLup: _lup() }); @@ -1180,7 +1180,7 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { from: _lender1, amount: 9_000 * 1e18, index: 2873, - lpAward: 8_994.177960110671668131 * 1e18, + lpAward: 8_994.229791354853043265 * 1e18, newLup: 601.252968524772188572 * 1e18 }); @@ -1189,10 +1189,10 @@ contract ERC20PoolQuoteTokenTest is ERC20HelperContract { _removeAllLiquidity({ from: _lender, - amount: 5_003.525624026555345183 * 1e18, + amount: 5_003.495432642728075897 * 1e18, index: 2873, newLup: 601.252968524772188572 * 1e18, - lpRedeem: 5_000.281794392950113758 * 1e18 + lpRedeem: 5_000.280437802026190445 * 1e18 }); _removeAllLiquidity({ diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolBorrow.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolBorrow.t.sol index 285b0cf8c..30be7660b 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolBorrow.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolBorrow.t.sol @@ -136,7 +136,7 @@ contract ERC721SubsetPoolBorrowTest is ERC721PoolBorrowTest { }); } - function testBorrowAndRepay() external { + function testBorrowAndRepay() external tearDown { // lender deposits 10000 Quote into 3 buckets _addInitialLiquidity({ @@ -275,11 +275,11 @@ contract ERC721SubsetPoolBorrowTest is ERC721PoolBorrowTest { htp: 502.333658244714424687 * 1e18, lup: _priceAt(2550), poolSize: 30_003.498905447098680000 * 1e18, - pledgedCollateral: Maths.wad(3), + pledgedCollateral: 3 * 1e18, encumberedCollateral: 0.500516446164039921 * 1e18, - poolDebt: 1507.000974734143274062 * 1e18, - actualUtilization: 0.050233397762005623 * 1e18, - targetUtilization: 0.166838815388013307 * 1e18, + poolDebt: 1_507.000974734143274062 * 1e18, + actualUtilization: 0.100096122026423251 * 1e18, + targetUtilization: 0.332446840033426268 * 1e18, minDebtAmount: 150.700097473414327406 * 1e18, loans: 1, maxBorrower: _borrower, @@ -349,12 +349,12 @@ contract ERC721SubsetPoolBorrowTest is ERC721PoolBorrowTest { PoolParams({ htp: 0, lup: MAX_PRICE, - poolSize: 30_005.083883677219590000 * 1e18, + poolSize: 30_005.088767154245370000 * 1e18, pledgedCollateral: 0, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 0.050227507786735589 * 1e18, - targetUtilization: 0.166838815388013307 * 1e18, + actualUtilization: 0.050227555333959397 * 1e18, + targetUtilization: 0.202597018753257617 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -363,9 +363,9 @@ contract ERC721SubsetPoolBorrowTest is ERC721PoolBorrowTest { }) ); _assertEMAs({ - debtColEma: 755_981.012555885345015825 * 1e18, - lupt0DebtEma: 4_531_205.827599034360703833 * 1e18, - debtEma: 1_507.000974734143274062 * 1e18, + debtColEma: 1_009_226.137898421530685238 * 1e18, + lupt0DebtEma: 4_981_446.144217726231751319 * 1e18, + debtEma: 1_507.002401317220586672 * 1e18, depositEma: 30_003.498902092092525534 * 1e18 }); // check bucket state after fully repay @@ -373,8 +373,8 @@ contract ERC721SubsetPoolBorrowTest is ERC721PoolBorrowTest { index: 2550, lpBalance: 10_000 * 1e18, collateral: 0, - deposit: 10_001.694627892406530000 * 1e18, - exchangeRate: 1.000169462789240653 * 1e18 + deposit: 10_001.696255718081790000 * 1e18, + exchangeRate: 1.000169625571808179 * 1e18 }); // check borrower info after fully repay _assertBorrower({ diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolCollateral.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolCollateral.t.sol index ab7441a50..58334c1c0 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolCollateral.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolCollateral.t.sol @@ -720,8 +720,8 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { pledgedCollateral: 2 * 1e18, encumberedCollateral: 5_992_754_428.551908353085520210 * 1e18, poolDebt: 598.294326419208615388 * 1e18, - actualUtilization: 2.990870666205084615 * 1e18, - targetUtilization: 2_995_775_262.887499112057200872 * 1e18, + actualUtilization: 0.750721153846153847 * 1e18, + targetUtilization: 0.328577182109433013 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), @@ -736,80 +736,80 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { index: 3060, lpBalance: 20 * 1e18, collateral: 0.0000000000000000000 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3061, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3062, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3063, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3064, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3065, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3066, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3067, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 66.832513309346669380 * 1e18, - exchangeRate: 3.341625665467333469 * 1e18 + deposit: 66.831193726562997920 * 1e18, + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3068, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 20.004183919163565300 * 1e18, - exchangeRate: 1.000209195958178265 * 1e18 + deposit: 20.003788944092390860 * 1e18, + exchangeRate: 1.000189447204619543 * 1e18 }); _assertBucket({ index: 3069, lpBalance: 20.0 * 1e18, collateral: 0.0 * 1e18, - deposit: 20.004183919163565300 * 1e18, - exchangeRate: 1.000209195958178265 * 1e18 + deposit: 20.003788944092390860 * 1e18, + exchangeRate: 1.000189447204619543 * 1e18 }); _assertBucket({ @@ -836,17 +836,17 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { _assertBucket({ index: 3060, lpBalance: 20.202020202020202020 * 1e18, - collateral: 0.285330970663516468 * 1e18, + collateral: 0.285325336911052408 * 1e18, deposit: 0, - exchangeRate: 3.341625665467333471 * 1e18 + exchangeRate: 3.341559686328149896 * 1e18 }); _assertBucket({ index: 3061, lpBalance: 20.202020202020202020 * 1e18, - collateral: 0.286757625516834048 * 1e18, + collateral: 0.286751963595607668 * 1e18, deposit: 0, - exchangeRate: 3.341625665467333471 * 1e18 + exchangeRate: 3.341559686328149900 * 1e18 }); _assertBucket({ @@ -868,8 +868,8 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { kickMomp: 0.000000099836282890 * 1e18, totalBondEscrowed: 5.907892673985352325 * 1e18, auctionPrice: 0.000004621809202112 * 1e18, - debtInAuction: 439.677389340513210329 * 1e18, - thresholdPrice: 385.776675964868418456 * 1e18, + debtInAuction: 439.681348088864224700 * 1e18, + thresholdPrice: 385.774399985858744599 * 1e18, neutralPrice: 310.164365384230997074 * 1e18 }) ); @@ -878,16 +878,16 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { PoolParams({ htp: 0, lup: 99836282890, - poolSize: 374.170934385060477538 * 1e18, - pledgedCollateral: 1.139719990175231268 * 1e18, - encumberedCollateral: 4403983968.683524073950025244 * 1e18, - poolDebt: 439.677389340513210329 * 1e18, - actualUtilization: 1.117110216223813782 * 1e18, - targetUtilization: 2_995_775_262.887499112057200872 * 1e18, + poolSize: 374.163546520999771310 * 1e18, + pledgedCollateral: 1.139736976079754220 * 1e18, + encumberedCollateral: 4404023621.084799631606156246 * 1e18, + poolDebt: 439.681348088864224700 * 1e18, + actualUtilization: 0.061025469820976144 * 1e18, + targetUtilization: 0.328577182109433013 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), - interestRate: 0.0605 * 1e18, + interestRate: 0.0495 * 1e18, interestRateUpdate: block.timestamp }) ); @@ -898,10 +898,10 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { _assertBorrower({ borrower: _borrower, - borrowerDebt: 439.677389340513210329 * 1e18, - borrowerCollateral: 1.139719990175231268 * 1e18, + borrowerDebt: 439.681348088864224700 * 1e18, + borrowerCollateral: 1.139736976079754220 * 1e18, borrowert0Np: 78.825721153846153882 * 1e18, - borrowerCollateralization: 0.000000000258792947 * 1e18, + borrowerCollateralization: 0.000000000258794474 * 1e18, tokenIds: borrowerTokenIds }); @@ -924,10 +924,10 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { _assertBorrower({ borrower: _borrower, - borrowerDebt: 439.677384764922100239 * 1e18, - borrowerCollateral: 0.139719990175231268 * 1e18, + borrowerDebt: 439.681343513273114610 * 1e18, + borrowerCollateral: 0.139736976079754220 * 1e18, borrowert0Np: 78.825721153846153882 * 1e18, - borrowerCollateralization: 0.000000000031725817 * 1e18, + borrowerCollateralization: 0.000000000031729389 * 1e18, tokenIds: borrowerTokenIds }); @@ -955,9 +955,9 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { kickTime: block.timestamp - (32 hours + 4210 minutes), kickMomp: 0.000000099836282890 * 1e18, totalBondEscrowed: 5.907892720203444346 * 1e18, - auctionPrice: 0 * 1e18, - debtInAuction: 439.677384764922100239 * 1e18, - thresholdPrice: 3_148.371989379999109069 * 1e18, + auctionPrice: 0, + debtInAuction: 439.681343513273114610 * 1e18, + thresholdPrice: 3_147.740272854337762554 * 1e18, neutralPrice: 310.164365384230997074 * 1e18 }) ); @@ -966,7 +966,7 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { from: _lender, borrower: _borrower, maxDepth: 10, - settledDebt: 111.717941412250938348 * 1e18 + settledDebt: 111.718947293453085984 * 1e18 }); _assertBorrower({ @@ -1002,9 +1002,9 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { _assertBucket({ index: 3060, lpBalance: 20.202020202020202020 * 1e18, - collateral: 0.285330970663516468 * 1e18, + collateral: 0.285325336911052408 * 1e18, deposit: 0, - exchangeRate: 3.341625665467333471 * 1e18 + exchangeRate: 3.341559686328149896 * 1e18 }); _assertLenderLpBalance({ lender: _borrower, @@ -1163,16 +1163,16 @@ contract ERC721PoolCollateralTest is ERC721HelperContract { PoolParams({ htp: 0, lup: MAX_PRICE, - poolSize: 50.000004575591109996 * 1e18, + poolSize: 50.000004575591110007 * 1e18, pledgedCollateral: 0, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 1.002468098960724093 * 1e18, - targetUtilization: 13_424_722_854.598244140780064966 * 1e18, + actualUtilization: 0.001552228747991919 * 1e18, + targetUtilization: 0.328577182109433013 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), - interestRate: 0.06655 * 1e18, + interestRate: 0.04455 * 1e18, interestRateUpdate: block.timestamp }) ); diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolEMAs.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolEMAs.t.sol index f26eb1cba..e9e869fd8 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolEMAs.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolEMAs.t.sol @@ -77,8 +77,8 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { pledgedCollateral: 6 * 1e18, encumberedCollateral: 4.620028820788372636 * 1e18, // 6 / 1.3 = 4.62 poolDebt: 6_954.361808414458420694 * 1e18, - actualUtilization: 0.586829404159407881 * 1e18, // moving -> 6_947 / 10_000 (meaningful) = 0.7 - targetUtilization: 0.769969644230769231 * 1e18, + actualUtilization: 0.000000000000000000 * 1e18, // moving -> 6_947 / 10_000 (meaningful) = 0.7 + targetUtilization: 1.000000000000000000 * 1e18, minDebtAmount: 695.436180841445842069 * 1e18, // debt / 10; only one loan, so not enforced loans: 1, maxBorrower: address(_borrower), @@ -87,9 +87,9 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { }) ); _assertEMAs({ - debtColEma: 8_059_788.606357480557372857 * 1e18, // 6_954^2 / 6 ~= 8_059_686 - lupt0DebtEma: 10_467_670.598117585349615039 * 1e18, // 1_505.26 * 6_954.04 ~= 10_467_638.25 - debtEma: 6_954.044264896858085302 * 1e18, // current debt with origination fee + debtColEma: 0.000000000000000000 * 1e18, // 6_954^2 / 6 ~= 8_059_686 + lupt0DebtEma: 0.000000000000000000 * 1e18, // 1_505.26 * 6_954.04 ~= 10_467_638.25 + debtEma: 0.000000000000000000 * 1e18, // current debt with origination fee // previous accumulator had updated to 15_000 before debt was drawn, but now 5_000 is no longer meaningful... depositEma: 11_850.197375262816985000 * 1e18 // ...so it is moving down toward 10_000 }); @@ -108,8 +108,8 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { pledgedCollateral: 6 * 1e18, encumberedCollateral: 4.620107931548236591 * 1e18, // small increase due to pending interest poolDebt: 6_954.480890971813258160 * 1e18, // small increase due to pending interest - actualUtilization: 0.586829404159407881 * 1e18, - targetUtilization: 0.769969644230769231 * 1e18, // debtColEma / lupt0DebtEma + actualUtilization: 0.000000000000000000 * 1e18, + targetUtilization: 1.000000000000000000 * 1e18, // debtColEma / lupt0DebtEma minDebtAmount: 695.448089097181325816 * 1e18, // small increase due to pending interest loans: 1, maxBorrower: address(_borrower), @@ -118,10 +118,10 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { }) ); _assertEMAs({ - debtColEma: 8_059_788.606357480557372857 * 1e18, // unchanged from setup - lupt0DebtEma: 10_467_670.598117585349615039 * 1e18, // unchanged from setup - debtEma: 6_954.044264896858085302 * 1e18, // unchanged from setup - depositEma: 11_850.197375262816985000 * 1e18 // unchanged from setup + debtColEma: 0.000000000000000000 * 1e18, // unchanged from setup + lupt0DebtEma: 0.000000000000000000 * 1e18, // unchanged from setup + debtEma: 0.000000000000000000 * 1e18, // unchanged from setup + depositEma: 11_850.197375262816985000 * 1e18 // unchanged from setup }); // touch the pool, triggering an interest accrual - EMAs should update @@ -130,11 +130,11 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { PoolParams({ htp: 1_159.080148495302209694 * 1e18, lup: _p1505_26, - poolSize: 15_000.38784582038918 * 1e18, // first interest accrual + poolSize: 15_000.371132163711890000 * 1e18, // first interest accrual pledgedCollateral: 6 * 1e18, encumberedCollateral: 4.620107931548236591 * 1e18, poolDebt: 6_954.480890971813258160 * 1e18, // pending interest now equals current interest - actualUtilization: 0.601778294656389596 * 1e18, + actualUtilization: 0.095745083902338016 * 1e18, targetUtilization: 0.769969644230769231 * 1e18, minDebtAmount: 695.448089097181325816 * 1e18, loans: 1, @@ -144,10 +144,10 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { }) ); _assertEMAs({ - debtColEma: 8_059_788.606357480557372857 * 1e18, // accumulator updated, no EMA change - lupt0DebtEma: 10_467_670.598117585349615039 * 1e18, // accumulator updated, no EMA change - debtEma: 6_954.044264896858085302 * 1e18, // accumulator updated, no EMA change - depositEma: 11_555.824340370334487364 * 1e18 // still moving toward 10_000 + debtColEma: 197_072.776194638866068935 * 1e18, // accumulator updated, EMA initialized + lupt0DebtEma: 255_948.760670328150445660 * 1e18, // accumulator updated, EMA initialized + debtEma: 1_106.413371029437537443 * 1e18, // accumulator updated, EMA initialized + depositEma: 11_555.824340370334487364 * 1e18 // still moving toward 10_000 }); (uint256 interestRate, ) = _pool.interestRateInfo(); assertEq(interestRate, 0.05 * 1e18); @@ -155,13 +155,13 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { skip(9 hours); // 12 hours since debt was drawn _pool.updateInterest(); _assertEMAs({ - debtColEma: 8_059_824.827133087800583978 * 1e18, // updated for interest accrual - lupt0DebtEma: 10_467_670.598117585349615039 * 1e18, // updated for interest accrual - debtEma: 6_954.221271554347056671 * 1e18, // updated for interest accrual - depositEma: 10_925.255918947232279645 * 1e18 // still moving toward 10_000 + debtColEma: 759_883.557390504783896613 * 1e18, // updated for interest accrual + lupt0DebtEma: 986_853.627682966275217023 * 1e18, // updated for interest accrual + debtEma: 3_477.199139105917836267 * 1e18, // updated for interest accrual + depositEma: 10_925.249143290274162648 * 1e18 // still moving toward 10_000 }); (interestRate, ) = _pool.interestRateInfo(); - assertEq(interestRate, 0.05 * 1e18); + assertEq(interestRate, 0.045 * 1e18); skip(6 hours); @@ -174,44 +174,44 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { _skipAndAccrue({ time: 4 hours, - mau: 0.552709628959737370 * 1e18, // dropping from 60% to 35% - tu: 0.769980648855063767 * 1e18, // still at 77% - rate: 0.05 * 1e18 + mau: 0.397622119994472546 * 1e18, // dropping from 60% to 35% + tu: 0.770035415811601449 * 1e18, // still at 77% + rate: 0.045 * 1e18 }); (, , , uint256 depositEma) = _pool.emasInfo(); - assertEq(depositEma, 12_582.630574533185444544 * 1e18); // now moving toward 20_000 + assertEq(depositEma, 12_582.608507963702724933 * 1e18); // now moving toward 20_000 _skipAndAccrue({ time: 20 hours, // 24 hours since liquidity was added - mau: 0.393730664447534871 * 1e18, // still dropping toward 35% - tu: 0.769999034610545182 * 1e18, // still at 77% - rate: 0.045 * 1e18 // first interest rate drop + mau: 0.358933852890687729 * 1e18, // still dropping toward 35% + tu: 0.770067458236015074 * 1e18, // still at 77% + rate: 0.0405 * 1e18 // dropping at 4.05% }); (, , , depositEma) = _pool.emasInfo(); - assertEq(depositEma, 17_664.401438069534311691 * 1e18); // still moving toward 20_000 + assertEq(depositEma, 17_664.344669688571758689 * 1e18); // still moving toward 20_000 _skipAndAccrue({ time: 2 days, // 3 days since liquidity was added - mau: 0.350326278385275702 * 1e18, // reached 35% - tu: 0.770061298755197770 * 1e18, // still at 77% - rate: 0.0405 * 1e18 // second interest rate drop + mau: 0.348388356770742011 * 1e18, // reached 35% + tu: 0.770135325994564531 * 1e18, // still at 77% + rate: 0.03645 * 1e18 // second interest rate drop }); (, , , depositEma) = _pool.emasInfo(); - assertEq(depositEma, 19_855.678232854988878203 * 1e18); // reached (sort of) 20_000 + assertEq(depositEma, 19_855.532581473734007629 * 1e18); // reached (sort of) 20_000 _assertPool( PoolParams({ - htp: 1_159.624091089473286060 * 1e18, + htp: 1_159.575642053959188547 * 1e18, lup: _p1505_26, - poolSize: 25_003.260972741349788790 * 1e18, // reflects additional 10_000 deposit + poolSize: 25_002.955913967460376246 * 1e18, // reflects additional 10_000 deposit pledgedCollateral: 6 * 1e18, - encumberedCollateral: 4.622276093514343199 * 1e18, - poolDebt: 6_957.744546536839716358 * 1e18, - actualUtilization: 0.350326278385275702 * 1e18, // dropped to 35% as expected - targetUtilization: 0.770061298755197770 * 1e18, - minDebtAmount: 695.774454653683971636 * 1e18, + encumberedCollateral: 4.622082975054377226 * 1e18, + poolDebt: 6_957.453852323755131280 * 1e18, + actualUtilization: 0.348388356770742011 * 1e18, // dropped to 35% as expected + targetUtilization: 0.770135325994564531 * 1e18, + minDebtAmount: 695.745385232375513128* 1e18, loans: 1, maxBorrower: address(_borrower), - interestRate: 0.0405 * 1e18, // dropped twice + interestRate: 0.03645 * 1e18, // dropped twice interestRateUpdate: _startTime + 98 hours }) ); @@ -234,45 +234,45 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { _skipAndAccrue({ time: 3 hours, - mau: 0.438034189478303512 * 1e18, // rising from 35% to 90% - tu: 0.783712586574747919 * 1e18, // increases as collateralization decreases - rate: 0.0405 * 1e18 + mau: 0.436398947261022405 * 1e18, // rising from 35% to 90% + tu: 0.794802131238362891 * 1e18, // increases as collateralization decreases + rate: 0.03645 * 1e18 }); (, , uint256 debtEma, ) = _pool.emasInfo(); - assertEq(debtEma, 8_707.751377089437009807 * 1e18); // increasing from 7_000 to 18_000 + assertEq(debtEma, 8_675.169506576032073392 * 1e18); // increasing from 7_000 to 18_000 _skipAndAccrue({ time: 9 hours, - mau: 0.625264252786034776 * 1e18, // still rising to 90% - tu: 0.817638199962595844 * 1e18, - rate: 0.0405 * 1e18 + mau: 0.624275651572709578 * 1e18, // still rising to 90% + tu: 0.846215553223533151 * 1e18, + rate: 0.03645 * 1e18 }); (, , debtEma, ) = _pool.emasInfo(); - assertEq(debtEma, 12_461.239878735709484526 * 1e18); // increasing from 7_000 to 18_000 + assertEq(debtEma, 12_441.391312587344397940 * 1e18); // increasing from 7_000 to 18_000 _skipAndAccrue({ time: 4 days, - mau: 0.897117712497350670 * 1e18, // reached 90% - tu: 0.947031347885781555 * 1e18, - rate: 0.0405 * 1e18 + mau: 0.897069303670436098 * 1e18, // reached 90% + tu: 0.966852816219664605 * 1e18, + rate: 0.032805 * 1e18 }); (, , debtEma, ) = _pool.emasInfo(); - assertEq(debtEma, 17_945.800561906185304271 * 1e18); // reached 18_000 + assertEq(debtEma, 17_944.480736533919717209 * 1e18); // reached 18_000 _assertPool( PoolParams({ - htp: 1_497.940412039697435044 * 1e18, + htp: 1_497.769957757345433425 * 1e18, lup: _p1505_26, - poolSize: 25_011.246566016078833928 * 1e18, + poolSize: 25_010.141517477798670592 * 1e18, pledgedCollateral: 12 * 1e18, // 6 additional NFTs deposited - encumberedCollateral: 11.941618338706780744 * 1e18, // all 12 NFTs are encumbered - poolDebt: 17_975.284944476369220528 * 1e18, // includes new debt - actualUtilization: 0.897117712497350670 * 1e18, - targetUtilization: 0.947031347885781555 * 1e18, - minDebtAmount: 1_797.528494447636922053 * 1e18, + encumberedCollateral: 11.940259472915000621 * 1e18, // all 12 NFTs are encumbered + poolDebt: 17_973.239493088145201104 * 1e18, // includes new debt + actualUtilization: 0.897069303670436098 * 1e18, + targetUtilization: 0.966852816219664605 * 1e18, + minDebtAmount: 1_797.323949308814520110 * 1e18, loans: 1, maxBorrower: address(_borrower), - interestRate: 0.0405 * 1e18, - interestRateUpdate: _startTime + 98 hours + interestRate: 0.032805 * 1e18, + interestRateUpdate: _startTime + 110 hours + 4 days }) ); } @@ -289,15 +289,15 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { }); _skipAndAccrue({ time: 40 hours, // 2 days after liquidity was added - mau: 0.744857048522821158 * 1e18, // 7_647 / 10_000 ~= 76% - tu: 0.793326272355691526 * 1e18, // starting at 77% + mau: 0.677110233556701963 * 1e18, // 7_647 / 10_000 ~= 76% + tu: 0.847585126397651853 * 1e18, // starting at 77% rate: 0.05 * 1e18 }); _assertEMAs({ - debtColEma: 8_539_491.492000790693673965 * 1e18, // reflects newly drawn debt - lupt0DebtEma: 10_764_160.711133073306706753 * 1e18, // unchanged from setup - debtEma: 7_585.487807318324588356 * 1e18, // increasing toward 7_647 - depositEma: 10_183.816911394801808573 * 1e18 // decreasing toward 10_000 + debtColEma: 2_745_524.266553065584517923 * 1e18, // reflects newly drawn debt + lupt0DebtEma: 3_239_231.294940137090747973 * 1e18, // unchanged from setup + debtEma: 6_895.559233472655919795 * 1e18, // increasing toward 7_647 + depositEma: 10_183.805962068972523753 * 1e18 // decreasing toward 10_000 }); // bad actor comes along and deposits large amount for 5 minutes, and then withdraws @@ -310,52 +310,53 @@ contract ERC721PoolEMAsTest is ERC721HelperContract { _pool.updateInterest(); // not really needed, since removing liquidity will trigger rate update _removeAllLiquidity({ from: _attacker, - amount: 150_000.003089440922870341 * 1e18, + amount: 150_000.003062917635863985 * 1e18, index: _i1505_26, newLup: _p1505_26, - lpRedeem: 149_972.484368509876401577 * 1e18 + lpRedeem: 149_973.669906855426845472 * 1e18 }); + uint256 rateChangeTs = block.timestamp; _skipAndAccrue({ time: 12, // skip a single block - mau: 0.695753471133465072 * 1e18, // impacted, but not enough to cause rate change - tu: 0.793367939903626038 * 1e18, - rate: 0.05 * 1e18 // rate unchanged + mau: 0.632791692026653958 * 1e18, // impacted, enough to cause rate change + tu: 0.847585617691556722 * 1e18, + rate: 0.045 * 1e18 // rate changed }); _assertEMAs({ - debtColEma: 8_540_370.017841347311996670 * 1e18, - lupt0DebtEma: 10_764_702.716470726509705193 * 1e18, - debtEma: 7_585.843823429738778980 * 1e18, - depositEma: 10_903.062849361711208755 * 1e18 // still noticably impacted + debtColEma: 2_750_544.877504425497154098 * 1e18, + lupt0DebtEma: 3_245_152.843668674754668559 * 1e18, + debtEma: 6_899.360444842923621304 * 1e18, + depositEma: 10_903.051559899926973925 * 1e18 // still noticably impacted }); _skipAndAccrue({ time: 12 hours, - mau: 0.729141586574051710 * 1e18, // moving back toward 75% - tu: 0.798822457321421405 * 1e18, - rate: 0.05 * 1e18 + mau: 0.696306196911713144 * 1e18, // moving back toward 75% + tu: 0.847637823306888876 * 1e18, + rate: 0.045 * 1e18 }); _assertEMAs({ - debtColEma: 8_656_142.490618553816291562 * 1e18, - lupt0DebtEma: 10_836_128.117434222666947215 * 1e18, - debtEma: 7_621.315210378439120928 * 1e18, - depositEma: 10_452.448949164988281908 * 1e18 // moving down back to 10_000 + debtColEma: 3_412_160.847313164565839074 * 1e18, + lupt0DebtEma: 4_025_493.853024754985190842 * 1e18, + debtEma: 7_278.073513801178223507 * 1e18, + depositEma: 10_452.403764437541109495 * 1e18 // moving down back to 10_000 }); _assertPool( PoolParams({ - htp: 1_276.218508787651473374 * 1e18, + htp: 1_276.209765166823398404 * 1e18, lup: _p1505_26, - poolSize: 15_002.306593887595200000 * 1e18, + poolSize: 15_002.177276783057210000 * 1e18, pledgedCollateral: 6 * 1e18, - encumberedCollateral: 5.087022896986824909 * 1e18, - poolDebt: 7_657.311052725908840244 * 1e18, // 7_647 principal plus some interest - actualUtilization: 0.729141586574051710 * 1e18, - targetUtilization: 0.798822457321421405 * 1e18, - minDebtAmount: 765.731105272590884024 * 1e18, + encumberedCollateral: 5.086988044805126619 * 1e18, + poolDebt: 7_657.258591000940390422 * 1e18, // 7_647 principal plus some interest + actualUtilization: 0.696306196911713144 * 1e18, + targetUtilization: 0.847637823306888876 * 1e18, + minDebtAmount: 765.725859100094039042 * 1e18, loans: 1, maxBorrower: address(_borrower), - interestRate: 0.05 * 1e18, - interestRateUpdate: _startTime + interestRate: 0.045 * 1e18, + interestRateUpdate: rateChangeTs }) ); } diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolInterest.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolInterest.t.sol index 13f63d486..fdaffd2d5 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolInterest.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolInterest.t.sol @@ -154,7 +154,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1.800750077529217167 * 1e18 }); - _assertLenderInterest(liquidityAdded, 10.004632566415800000 * 1e18); + _assertLenderInterest(liquidityAdded, 10.004595693661100000 * 1e18); // borrower borrows some additional quote after some time has passed skip(10 days); @@ -178,7 +178,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1.500002057800446964 * 1e18 }); - _assertLenderInterest(liquidityAdded, 14.290569428855550000 * 1e18); + _assertLenderInterest(liquidityAdded, 14.290532556069200000 * 1e18); // mint additional quote to borrower to enable repayment deal(address(_quote), _borrower, 20_000 * 1e18); @@ -352,7 +352,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1.197213816827790670 * 1e18 }); - _assertLenderInterest(liquidityAdded, 0.371927286666690000 * 1e18); + _assertLenderInterest(liquidityAdded, 0.365554305676230000 * 1e18); skip(4 hours); @@ -361,7 +361,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { from: _lender, amount: 1 * 1e18, index: 2550, - lpAward: 0.999978744441788346 * 1e18, + lpAward: 0.999979133938993539 * 1e18, newLup: 2995.912459898389633881 * 1e18 }); liquidityAdded += 1e18; @@ -372,7 +372,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { (poolDebt,,,) = _pool.debtInfo(); assertEq(poolDebt, expectedPoolDebt); - _assertLenderInterest(liquidityAdded, 0.637680300600360000 * 1e18); + _assertLenderInterest(liquidityAdded, 0.625994892241440000 * 1e18); expectedBorrower1Debt = 8_008.240798551896146546 * 1e18; @@ -556,7 +556,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 2.404169939255701731 * 1e18 }); - _assertLenderInterest(liquidityAdded, 25.750896517609250000 * 1e18); + _assertLenderInterest(liquidityAdded, 25.779680075333500000 * 1e18); // borrower pulls some of their collateral after some time has passed skip(10 days); @@ -581,7 +581,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1.801327695821111558 * 1e18 }); - _assertLenderInterest(liquidityAdded, 30.031168354510400000 * 1e18); + _assertLenderInterest(liquidityAdded, 30.059922094508300000 * 1e18); // borrower borrows some additional quote after some time has passed skip(10 days); @@ -605,7 +605,7 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1.500545633513497515 * 1e18 }); - _assertLenderInterest(liquidityAdded, 33.887067044166600000 * 1e18); + _assertLenderInterest(liquidityAdded, 33.915820770203100000 * 1e18); // mint additional quote to borrower to enable repayment deal(address(_quote), _borrower, 20_000 * 1e18); @@ -633,6 +633,6 @@ contract ERC721PoolSubsetInterestTest is ERC721PoolInterestTest { borrowerCollateralization: 1 * 1e18 }); - _assertLenderInterest(liquidityAdded, 38.052830597199800000 * 1e18); + _assertLenderInterest(liquidityAdded, 38.081584308182850000 * 1e18); } } diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsDepositTake.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsDepositTake.t.sol index 2bd1218dd..2cebb27e1 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsDepositTake.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsDepositTake.t.sol @@ -163,8 +163,8 @@ contract ERC721PoolLiquidationsDepositTakeTest is ERC721HelperContract { pledgedCollateral: 5 * 1e18, encumberedCollateral: 4.056751649452525709 * 1e18, poolDebt: 40.231555971534224231 * 1e18, - actualUtilization: 0.00055111720508951 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000477170706006322 * 1e18, + targetUtilization: 0.786051641950380194 * 1e18, minDebtAmount: 4.023155597153422423 * 1e18, loans: 1, maxBorrower: address(_borrower2), diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsKick.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsKick.t.sol index 299e19453..4ff5963c3 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsKick.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsKick.t.sol @@ -183,8 +183,8 @@ contract ERC721PoolLiquidationsKickTest is ERC721HelperContract { pledgedCollateral: 5 * 1e18, encumberedCollateral: 4.056751649452525709 * 1e18, poolDebt: 40.231555971534224231 * 1e18, - actualUtilization: 0.00055111720508951 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000477170706006322 * 1e18, + targetUtilization: 0.786051641950380194 * 1e18, minDebtAmount: 4.023155597153422423 * 1e18, loans: 1, maxBorrower: address(_borrower2), diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettle.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettle.t.sol index 02164c30b..08b173dce 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettle.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettle.t.sol @@ -257,8 +257,8 @@ contract ERC721PoolLiquidationsSettleTest is ERC721HelperContract { pledgedCollateral: 1 * 1e18, encumberedCollateral: 0, poolDebt: 0, - actualUtilization: 0.389471335647237918 * 1e18, - targetUtilization: 0.656073460432016344 * 1e18, + actualUtilization: 0, + targetUtilization: 1 * 1e18, minDebtAmount: 0, loans: 0, maxBorrower: address(0), diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettleAuction.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettleAuction.t.sol index da90ec96b..4ae5172cc 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettleAuction.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsSettleAuction.t.sol @@ -415,14 +415,14 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract { _assertBucket({ index: 2501, lpBalance: 2_000 * 1e18, - collateral: 0.110649792292326223 * 1e18, - deposit: 1_575.729229030217308768 * 1e18, - exchangeRate: 1.000557427154164986 * 1e18 + collateral: 0.110639687749865566 * 1e18, + deposit: 1_575.596009456533555165 * 1e18, + exchangeRate: 1.000471394253082551 * 1e18 }); _assertBucket({ index: MAX_FENWICK_INDEX, - lpBalance: 4132730466, - collateral: 0.041395075478140787 * 1e18, + lpBalance: 4133739266, + collateral: 0.041405180020601444 * 1e18, deposit: 0, exchangeRate: 1 * 1e18 }); @@ -550,7 +550,7 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract { borrower: _borrower, borrowerDebt: 425.172014916344732952 * 1e18, borrowerCollateral: 3 * 1e18, - borrowert0Np: 149.491518364962118535 * 1e18, + borrowert0Np: 148.074537148232619781 * 1e18, borrowerCollateralization: 27.126189445355815944 * 1e18 }); _assertAuction( @@ -599,9 +599,9 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract { _addLiquidityWithPenalty({ from: _lender, amount: 1000 * 1e18, - amountAdded: 999.849315068493151000 * 1e18, + amountAdded: 999.876712328767123000 * 1e18, index: 6113, - lpAward: 999.849315068493151000 * 1e18, + lpAward: 999.876712328767123000 * 1e18, newLup: 3_844.432207828138682757 * 1e18 }); uint256[] memory removalIndexes = new uint256[](2); @@ -1249,9 +1249,9 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract { _assertBucket({ index: 2500, lpBalance: 4_997.115384615384614000 * 1e18, - collateral: 0.886287035829988542 * 1e18, - deposit: 1_574.488096437633785035 * 1e18, - exchangeRate: 1.000336091874601493 * 1e18 + collateral: 0.886214193313763368 * 1e18, + deposit: 1_574.549120144393919177 * 1e18, + exchangeRate: 1.000291983507608180 * 1e18 }); _assertBucket({ index: 2502, @@ -1262,8 +1262,8 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract { }); _assertBucket({ index: 7388, - lpBalance: 0.000000036608930253 * 1e18, - collateral: 0.366689636201052678 * 1e18, + lpBalance: 0.000000036616202579 * 1e18, + collateral: 0.366762478717277852 * 1e18, deposit: 0, exchangeRate: 1 * 1e18 }); diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsTake.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsTake.t.sol index 9cb9a9117..1781b565d 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsTake.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolLiquidationsTake.t.sol @@ -189,8 +189,8 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { pledgedCollateral: 5 * 1e18, encumberedCollateral: 4.056751649452525709 * 1e18, poolDebt: 40.231555971534224231 * 1e18, - actualUtilization: 0.00055111720508951 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000477170706006322 * 1e18, + targetUtilization: 0.786051641950380194 * 1e18, minDebtAmount: 4.023155597153422423 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -292,12 +292,12 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { PoolParams({ htp: 7.749209044755361552 * 1e18, lup: 9.917184843435912074 * 1e18, - poolSize: 73_004.347853842247224958 * 1e18, + poolSize: 73_004.347853838043123634 * 1e18, pledgedCollateral: 4 * 1e18, encumberedCollateral: 2.517692578855560848 * 1e18, poolDebt: 24.968422683457442924 * 1e18, - actualUtilization: 0.000551108273306260 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000411519999179138 * 1e18, + targetUtilization: 0.781984313351887130 * 1e18, minDebtAmount: 1.248421134172872146 * 1e18, loans: 2, maxBorrower: address(_borrower), @@ -364,12 +364,12 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { PoolParams({ htp: 5.739737879567360457 * 1e18, lup: 9.917184843435912074 * 1e18, - poolSize: 73_004.347853842247224958 * 1e18, + poolSize: 73_004.347853838043123634 * 1e18, pledgedCollateral: 3.0 * 1e18, encumberedCollateral: 1.736300564176668638 * 1e18, poolDebt: 17.219213638702081372 * 1e18, - actualUtilization: 0.000551108273306260 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000411519999179138 * 1e18, + targetUtilization: 0.781984313351887130 * 1e18, minDebtAmount: 1.721921363870208137 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -467,8 +467,8 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { pledgedCollateral: 5 * 1e18, encumberedCollateral: 4.056751649452525709 * 1e18, poolDebt: 40.231555971534224231 * 1e18, - actualUtilization: 0.00055111720508951 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000477170706006322 * 1e18, + targetUtilization: 0.786051641950380194 * 1e18, minDebtAmount: 4.023155597153422423 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -573,12 +573,12 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { PoolParams({ htp: 5.739870563397816903 * 1e18, lup: 9.917184843435912074 * 1e18, - poolSize: 73_004.348644408093384607 * 1e18, + poolSize: 73_004.348644400449318457 * 1e18, pledgedCollateral: 3 * 1e18, encumberedCollateral: 4.070504644882883983 * 1e18, poolDebt: 40.367946969368016673 * 1e18, - actualUtilization: 0.000551102806362854 * 1e18, - targetUtilization: 0.911373730814237973 * 1e18, + actualUtilization: 0.000371331832771808 * 1e18, + targetUtilization: 0.778640404875432888 * 1e18, minDebtAmount: 4.036794696936801667 * 1e18, loans: 1, maxBorrower: address(_borrower2), @@ -653,14 +653,14 @@ contract ERC721PoolLiquidationsTakeTest is ERC721HelperContract { changePrank(_lender); // Kicker claims bond + reward and transfer to a different address - _pool.withdrawBonds(_withdrawRecipient, type(uint256).max); - assertEq(_quote.balanceOf(_withdrawRecipient), 0.242202920686750816 * 1e18); + _pool.withdrawBonds(_withdrawRecipient, 0.1 * 1e18); + assertEq(_quote.balanceOf(_withdrawRecipient), 0.1 * 1e18); - vm.revertTo(snapshot); - - // Kicker claims bond + reward + // Kicker claims remaining bond + reward to his own address _pool.withdrawBonds(_lender, type(uint256).max); - assertEq(_quote.balanceOf(_lender), 46_998.523343483554970812 * 1e18); + assertEq(_quote.balanceOf(_lender), 46_998.423343483554970812 * 1e18); + + vm.revertTo(snapshot); // revert to ensure tear down has enough balance in pool } function testTakeCollateralSubsetPoolAndSettleByRepayAndPledge() external tearDown { diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolPurchaseQuote.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolPurchaseQuote.t.sol index bc5ebbfe1..acd448d01 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolPurchaseQuote.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolPurchaseQuote.t.sol @@ -257,7 +257,7 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { uint256 amountToPurchase = 10_100 * 1e18; assertGt(_quote.balanceOf(address(_pool)), amountToPurchase); - uint256 amountWithInterest = 24_002.859358364989920000 * 1e18; + uint256 amountWithInterest = 24_002.693295339317544000 * 1e18; _addCollateral({ from: _bidder, @@ -273,7 +273,7 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { amount: amountWithInterest, index: 2350, newLup: _priceAt(2352), - lpRedeem: 24_000.858274845540873331 * 1e18 + lpRedeem: 24_000.762569742914924690 * 1e18 }); assertEq(_quote.balanceOf(_bidder), amountWithInterest); @@ -281,10 +281,10 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { // check bucket state _assertBucket({ index: 2350, - lpBalance: 32_653.618582201813497294 * 1e18, + lpBalance: 32_653.714287304439445935 * 1e18, collateral: Maths.wad(4), deposit: 0, - exchangeRate: 1.000083375498348170 * 1e18 + exchangeRate: 1.000080444343832501 * 1e18 }); // bidder withdraws unused collateral @@ -292,13 +292,13 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { from: _bidder, amount: 1, index: 2350, - lpRedeem: 8_163.404645550453371392 * 1e18 + lpRedeem: 8_163.428571826109864353 * 1e18 }); _assertLenderLpBalance({ lender: _bidder, index: 2350, - lpBalance: 490.213936651360125902 * 1e18, + lpBalance: 490.285715478329581582 * 1e18, depositTime: _startTime + 25 hours }); @@ -310,13 +310,13 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { from: _lender, amount: 1, index: 2350, - lpRedeem: 8_163.404645550453371392 * 1e18 + lpRedeem: 8_163.428571826109864353 * 1e18 }); _assertLenderLpBalance({ lender: _bidder, index: 2350, - lpBalance: 490.213936651360125902 * 1e18, + lpBalance: 490.285715478329581582 * 1e18, depositTime: _startTime + 25 hours }); @@ -325,10 +325,10 @@ contract ERC721PoolPurchaseQuoteTest is ERC721HelperContract { // check bucket state _assertBucket({ index: 2350, - lpBalance: 16_326.809291100906754510 * 1e18, + lpBalance: 16_326.857143652219717229 * 1e18, collateral: Maths.wad(2), deposit: 0, - exchangeRate: 1.000083375498348169 * 1e18 + exchangeRate: 1.000080444343832502 * 1e18 }); // should revert if lender2 attempts to remove more collateral than lp is available for diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolReserveAuction.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolReserveAuction.t.sol index 28a2f5219..9e34bf724 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolReserveAuction.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolReserveAuction.t.sol @@ -344,7 +344,7 @@ contract ERC721PoolReserveAuctionTest is ERC721HelperContract { }); } - function testReserveAuctionPartiallyTaken() external { + function testReserveAuctionPartiallyTaken() external tearDown { // borrower repays partial debt (auction for full reserves) _repayDebt({ from: _borrower, @@ -425,7 +425,7 @@ contract ERC721PoolReserveAuctionTest is ERC721HelperContract { from: _borrower, borrower: _borrower, amountToRepay: 105_000 * 1e18, - amountRepaid: 79_940.029064520279557316 * 1e18, + amountRepaid: 79_975.078950647281196428 * 1e18, collateralToPull: 0, newLup: MAX_PRICE }); @@ -433,7 +433,7 @@ contract ERC721PoolReserveAuctionTest is ERC721HelperContract { // start an auction, confirm old claimable reserves are included alongside new claimable reserves skip(1 days); - reserves = 442.238729377484010623 * 1e18; + reserves = 426.739865239988891464 * 1e18; uint256 newClaimableReserves = reserves; _assertReserveAuction({ reserves: reserves, @@ -452,9 +452,11 @@ contract ERC721PoolReserveAuctionTest is ERC721HelperContract { epoch: 2 }); + uint256 snapshot = vm.snapshot(); + // take everything skip(28 hours); - assertEq(expectedReserves, 767.113079809103242756 * 1e18); + assertEq(expectedReserves, 751.769204312983074788 * 1e18); expectedPrice = 3.725290298461914062 * 1e18; _assertReserveAuction({ reserves: 0, @@ -478,5 +480,7 @@ contract ERC721PoolReserveAuctionTest is ERC721HelperContract { auctionPrice: expectedPrice, timeRemaining: 44 hours }); + + vm.revertTo(snapshot); // revert to ensure tearDown has enough balance in pool } } diff --git a/tests/forge/unit/PositionManager.t.sol b/tests/forge/unit/PositionManager.t.sol index 72833270e..bf3aa409b 100644 --- a/tests/forge/unit/PositionManager.t.sol +++ b/tests/forge/unit/PositionManager.t.sol @@ -1943,7 +1943,7 @@ contract PositionManagerERC20PoolTest is PositionManagerERC20PoolHelperContract _assertLenderLpBalance({ lender: address(_positionManager), index: moveIndex, - lpBalance: 1_999.870115955512239554 * 1e18, + lpBalance: 1_999.865897356084855977 * 1e18, depositTime: _startTime }); skip(1 weeks); diff --git a/tests/forge/unit/Rewards/RewardsManager.t.sol b/tests/forge/unit/Rewards/RewardsManager.t.sol index f6892ac12..4100e9f28 100644 --- a/tests/forge/unit/Rewards/RewardsManager.t.sol +++ b/tests/forge/unit/Rewards/RewardsManager.t.sol @@ -441,7 +441,7 @@ contract RewardsManagerTest is RewardsHelperContract { borrowAmount: 300 * 1e18, limitIndex: 2555, pool: address(_pool), - tokensToBurn: 150.804205428530300439 * 1e18 + tokensToBurn: 150.531521503946490109 * 1e18 }); // check owner can withdraw the NFT and rewards will be automatically claimed @@ -450,9 +450,9 @@ contract RewardsManagerTest is RewardsHelperContract { pool: address(_pool), tokenId: tokenIdOne, claimedArray: _epochsClaimedArray(2, 0), - reward: 78.852344077558527016 * 1e18, + reward: 78.702367919037406995 * 1e18, indexes: depositIndexes, - updateExchangeRatesReward: 3.450241363293378951 * 1e18 + updateExchangeRatesReward: 3.436607167064188546 * 1e18 }); } @@ -524,7 +524,7 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater, pool: address(_pool), indexes: depositIndexes, - reward: 3.399633583097821167 * 1e18 + reward: 3.399661193610840835 * 1e18 }); } @@ -695,7 +695,7 @@ contract RewardsManagerTest is RewardsHelperContract { index: _i9_81, lpBalance: 10_000 * 1e18, collateral: 0, - deposit: 4_936.865619773958005817 * 1e18, + deposit: 4_936.865619773958009217 * 1e18, exchangeRate: 0.493686561977395801 * 1e18 }); @@ -976,7 +976,7 @@ contract RewardsManagerTest is RewardsHelperContract { // trigger second reserve auction totalTokensBurned += _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 753.761937534761336922 * 1e18, + tokensToBurn: 749.938886647400234043 * 1e18, borrowAmount: 1_500 * 1e18, limitIndex: 6_000, pool: address(_pool) @@ -987,13 +987,13 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater, pool: address(_pool), indexes: depositIndexes, - reward: 17.238252336072314418 * 1e18 + reward: 17.047099791704330880 * 1e18 }); - assertEq(_ajnaToken.balanceOf(_updater), 37.688096876738003300 * 1e18); + assertEq(_ajnaToken.balanceOf(_updater), 37.496944332370019762 * 1e18); // check available rewards rewardsEarned = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); - assertEq(rewardsEarned, 376.880968767380567488 * 1e18); + assertEq(rewardsEarned, 374.969443323700090181 * 1e18); assertLt(rewardsEarned, Maths.wmul(totalTokensBurned, 0.800000000000000000 * 1e18)); /*****************************/ @@ -1003,7 +1003,7 @@ contract RewardsManagerTest is RewardsHelperContract { // trigger third reserve auction totalTokensBurned += _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 1_034.145224534232837796 * 1e18, + tokensToBurn: 1_030.322190308494974315 * 1e18, borrowAmount: 1_500 * 1e18, limitIndex: 6_000, pool: address(_pool) @@ -1011,7 +1011,7 @@ contract RewardsManagerTest is RewardsHelperContract { // skip updating exchange rates and check available rewards uint256 rewardsEarnedNoUpdate = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); - assertEq(rewardsEarnedNoUpdate, 376.880968767380567488 * 1e18); + assertEq(rewardsEarnedNoUpdate, 374.969443323700090181 * 1e18); assertLt(rewardsEarned, Maths.wmul(totalTokensBurned, 0.800000000000000000 * 1e18)); // snapshot calling update exchange rate @@ -1022,10 +1022,10 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater2, pool: address(_pool), indexes: depositIndexes, - reward: 14.019164349973606338 * 1e18 + reward: 14.019165183054794390 * 1e18 }); - assertEq(_ajnaToken.balanceOf(_updater2), 14.019164349973606338 * 1e18); + assertEq(_ajnaToken.balanceOf(_updater2), 14.019165183054794390 * 1e18); // check available rewards rewardsEarned = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); @@ -1042,7 +1042,7 @@ contract RewardsManagerTest is RewardsHelperContract { // triger fourth reserve auction totalTokensBurned += _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 1_289.513636917170056104 * 1e18, + tokensToBurn: 1_285.690624286578714549 * 1e18, borrowAmount: 1_500 * 1e18, limitIndex: 6_000, pool: address(_pool) @@ -1050,7 +1050,7 @@ contract RewardsManagerTest is RewardsHelperContract { // check rewards earned rewardsEarned = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); - assertEq(rewardsEarned, 376.880968767380567488 * 1e18); + assertEq(rewardsEarned, 374.969443323700090181 * 1e18); // call update exchange rate _updateExchangeRates({ @@ -1063,7 +1063,7 @@ contract RewardsManagerTest is RewardsHelperContract { // check rewards earned won't increase since previous update was missed rewardsEarned = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); - assertEq(rewardsEarned, 376.880968767380567488 * 1e18); + assertEq(rewardsEarned, 374.969443323700090181 * 1e18); /*****************************/ /*** Fifth Reserve Auction ***/ @@ -1072,7 +1072,7 @@ contract RewardsManagerTest is RewardsHelperContract { // triger fifth reserve auction totalTokensBurned += _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 1521.830620022508618175 * 1e18, + tokensToBurn: 1_518.007628131033839702 * 1e18, borrowAmount: 1_500 * 1e18, limitIndex: 6_000, pool: address(_pool) @@ -1083,12 +1083,12 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater2, pool: address(_pool), indexes: depositIndexes, - reward: 11.615849155266905358 * 1e18 + reward: 11.615850192222782234 * 1e18 }); - assertEq(_ajnaToken.balanceOf(_updater2), 11.615849155266905358 * 1e18); + assertEq(_ajnaToken.balanceOf(_updater2), 11.615850192222782234 * 1e18); rewardsEarned = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); - assertEq(rewardsEarned, 493.039460320049744942 * 1e18); + assertEq(rewardsEarned, 491.127945245927630407 * 1e18); // claim all rewards accrued since deposit _claimRewards({ @@ -1096,7 +1096,7 @@ contract RewardsManagerTest is RewardsHelperContract { from: _minterOne, tokenId: tokenIdOne, epochsClaimed: _epochsClaimedArray(5,0), - reward: 493.039460320049744942 * 1e18 + reward: 491.127945245927630407 * 1e18 }); assertEq(_ajnaToken.balanceOf(_minterOne), rewardsEarned); assertLt(rewardsEarned, Maths.wmul(totalTokensBurned, 0.800000000000000000 * 1e18)); @@ -1192,11 +1192,11 @@ contract RewardsManagerTest is RewardsHelperContract { // retrieve the position managers index set, recreating typical tx flow since positionIndexes are stored unordered in EnnumerableSets secondIndexes = _positionManager.getPositionIndexes(tokenIdOne); - secondLpsAwarded[0] = 1_000.000164743206012000 * 1e18; - secondLpsAwarded[1] = 1_006.443804104948552000 * 1e18; - secondLpsAwarded[2] = 1_000.000164743206012000 * 1e18; - secondLpsAwarded[3] = 1_000.000164743206012000 * 1e18; - secondLpsAwarded[4] = 1_000.000164743206012000 * 1e18; + secondLpsAwarded[0] = 1_000.000165321954673000 * 1e18; + secondLpsAwarded[1] = 1_006.443804687426460000 * 1e18; + secondLpsAwarded[2] = 1_000.000165321954673000 * 1e18; + secondLpsAwarded[3] = 1_000.000165321954673000 * 1e18; + secondLpsAwarded[4] = 1_000.000165321954673000 * 1e18; _moveStakedLiquidity({ from: _minterOne, @@ -1216,7 +1216,7 @@ contract RewardsManagerTest is RewardsHelperContract { // second reserve auction happens successfully -> epoch 1 _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 149.275382184037345529 * 1e18, + tokensToBurn: 149.002721220086908460 * 1e18, borrowAmount: 300 * 1e18, limitIndex: 2555, pool: address(_pool) @@ -1233,7 +1233,7 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater, pool: address(_pool), indexes: depositIndexes, - reward: 3.373279477974559345 * 1e18 + reward: 3.359647161647741986 * 1e18 }); /*********************/ @@ -1244,7 +1244,7 @@ contract RewardsManagerTest is RewardsHelperContract { from: _minterOne, tokenId: tokenIdOne, epochsClaimed: _epochsClaimedArray(1,1), - reward: 33.732794779745615314 * 1e18 + reward: 33.596471616477451732 * 1e18 }); } @@ -1320,7 +1320,7 @@ contract RewardsManagerTest is RewardsHelperContract { _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 133.010293986888191760 * 1e18, + tokensToBurn: 133.011310982683297932 * 1e18, borrowAmount: 300 * 1e18, limitIndex: 2555, pool: address(_pool) @@ -1332,24 +1332,24 @@ contract RewardsManagerTest is RewardsHelperContract { pool: address(_pool), tokenId: tokenIdTwo, claimedArray: _epochsClaimedArray(1, 0), - reward: 39.906015449635223195 * 1e18, + reward: 39.906320577094451437 * 1e18, indexes: depositIndexes, - updateExchangeRatesReward: 6.651002176006408713 * 1e18 + updateExchangeRatesReward: 6.651053030580225818 * 1e18 }); uint256 minterTwoBalance = _ajnaToken.balanceOf(_minterTwo); - assertEq(minterTwoBalance, 39.906015449635223195 * 1e18); + assertEq(minterTwoBalance, 39.906320577094451437 * 1e18); _unstakeToken({ owner: _minterThree, pool: address(_pool), tokenId: tokenIdThree, claimedArray: _epochsClaimedArray(1, 0), - reward: 33.250133719815196731 * 1e18, + reward: 33.250387944827385443 * 1e18, indexes: depositIndexes, updateExchangeRatesReward: 0 }); uint256 minterThreeBalance = _ajnaToken.balanceOf(_minterThree); - assertEq(minterThreeBalance, 33.250133719815196731 * 1e18); + assertEq(minterThreeBalance, 33.250387944827385443 * 1e18); assertGt(minterTwoBalance, minterThreeBalance); } @@ -1416,7 +1416,7 @@ contract RewardsManagerTest is RewardsHelperContract { owner: _minterTwo, tokenId: tokenIdTwo }); - assertEq(_ajnaToken.balanceOf(_minterTwo), 8.154797961459423073 * 1e18); + assertEq(_ajnaToken.balanceOf(_minterTwo), 8.154804173752250280 * 1e18); // calculate rewards earned since exchange rates have been updated uint256 idOneRewardsAtOne = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); @@ -1439,7 +1439,7 @@ contract RewardsManagerTest is RewardsHelperContract { // conduct second reserve auction uint256 secondTokensToBurn = _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 176.189760225502880454 * 1e18, + tokensToBurn: 175.886535409777500511 * 1e18, borrowAmount: 300 * 1e18, limitIndex: 3, pool: address(_pool) @@ -1471,11 +1471,11 @@ contract RewardsManagerTest is RewardsHelperContract { uint256 idOneRewardsAtTwo = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); assertLt(idOneRewardsAtTwo, secondTokensToBurn); assertGt(idOneRewardsAtTwo, 0); - assertEq(idOneRewardsAtTwo, 23.615632136163281165 * 1e18); + assertEq(idOneRewardsAtTwo, 23.539744751129506689 * 1e18); uint256 idTwoRewardsAtTwo = _rewardsManager.calculateRewards(tokenIdTwo, _pool.currentBurnEpoch()); assertLt(idOneRewardsAtTwo + idTwoRewardsAtTwo, secondTokensToBurn); - assertEq(idTwoRewardsAtTwo, 23.583081554200477722 * 1e18); + assertEq(idTwoRewardsAtTwo, 23.507298745456577468 * 1e18); assertGt(idTwoRewardsAtTwo, 0); // minter one claims rewards accrued after second auction @@ -1484,7 +1484,7 @@ contract RewardsManagerTest is RewardsHelperContract { from: _minterOne, tokenId: tokenIdOne, epochsClaimed: _epochsClaimedArray(1,1), - reward: 23.615632136163281165 * 1e18 + reward: 23.539744751129506689 * 1e18 }); assertEq(_ajnaToken.balanceOf(_minterOne), idOneRewardsAtOne + idOneRewardsAtTwo); @@ -1497,7 +1497,7 @@ contract RewardsManagerTest is RewardsHelperContract { epochsClaimed: _epochsClaimedArray(1,1), reward: idTwoRewardsAtTwo }); - assertEq(_ajnaToken.balanceOf(_minterTwo), 31.737879515659900795 * 1e18); + assertEq(_ajnaToken.balanceOf(_minterTwo), 31.662102919208827748 * 1e18); // check there are no remaining rewards available after claiming uint256 remainingRewards = _rewardsManager.calculateRewards(tokenIdOne, _pool.currentBurnEpoch()); @@ -1594,7 +1594,7 @@ contract RewardsManagerTest is RewardsHelperContract { // auction two uint256 tokensToBurnE2 = _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 308.672122067616182565 * 1e18, + tokensToBurn: 308.524022190658113598 * 1e18, borrowAmount: 1_000 * 1e18, limitIndex: 2555, pool: address(_pool) @@ -1604,22 +1604,22 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater, pool: address(_pool), indexes: depositIndexes, - reward: 11.343637195247653990 * 1e18 + reward: 11.336232201399613917 * 1e18 }); _assertBurn({ pool: address(_pool), epoch: 2, timestamp: block.timestamp - 24 hours, - burned: 308.672122067616182565 * 1e18, + burned: 308.524022190658113598 * 1e18, tokensToBurn: tokensToBurnE2, - interest: 23.936044239893182713 * 1e18 + interest: 23.938554041534910348 * 1e18 }); // auction three uint256 tokensToBurnE3 = _triggerReserveAuctions({ borrower: _borrower, - tokensToBurn: 676.658832743043390869 * 1e18, + tokensToBurn: 676.510732923020389616 * 1e18, borrowAmount: 2_000 * 1e18, limitIndex: 2555, pool: address(_pool) @@ -1629,16 +1629,16 @@ contract RewardsManagerTest is RewardsHelperContract { updater: _updater, pool: address(_pool), indexes: depositIndexes, - reward: 18.399335533771072810 * 1e18 + reward: 18.399335536618388154 * 1e18 }); _assertBurn({ pool: address(_pool), epoch: 3, timestamp: block.timestamp - 24 hours, - burned: 676.658832743043390869 * 1e18, + burned: 676.510732923020389616 * 1e18, tokensToBurn: tokensToBurnE3, - interest: 52.421031459480795903 * 1e18 + interest: 52.423541260157607958 * 1e18 }); // both stakers claim rewards @@ -1647,7 +1647,7 @@ contract RewardsManagerTest is RewardsHelperContract { pool: address(_pool), tokenId: tokenIdOne, claimedArray: _epochsClaimedArray(3, 0), - reward: 51.511621814050026070 * 1e18, + reward: 51.499282055430577895 * 1e18, indexes: firstIndexes, updateExchangeRatesReward: 0 }); @@ -1657,7 +1657,7 @@ contract RewardsManagerTest is RewardsHelperContract { pool: address(_pool), tokenId: tokenIdTwo, claimedArray: _epochsClaimedArray(3, 0), - reward: 286.817794557471160695 * 1e18, + reward: 286.756084406079436885 * 1e18, indexes: secondIndexes, updateExchangeRatesReward: 0 });