diff --git a/tests/forge/invariants/base/handlers/unbounded/BaseHandler.sol b/tests/forge/invariants/base/handlers/unbounded/BaseHandler.sol index 76a0681bb..3f059f30e 100644 --- a/tests/forge/invariants/base/handlers/unbounded/BaseHandler.sol +++ b/tests/forge/invariants/base/handlers/unbounded/BaseHandler.sol @@ -14,6 +14,7 @@ import { MAX_PRICE, MIN_PRICE, _indexOf, + _htp, _isCollateralized } from 'src/libraries/helpers/PoolHelper.sol'; import { Maths } from 'src/libraries/internal/Maths.sol'; @@ -546,7 +547,8 @@ abstract contract BaseHandler is Test { if (pendingFactor == 1e18) return; // get TP of worst loan - uint256 htp = _poolInfo.htp(address(_pool)); + (uint256 inflator, ) = _pool.inflatorInfo(); + uint256 htp = _htp(_getLoansInfo().maxT0DebtToCollateral, inflator); uint256 accrualIndex; diff --git a/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol b/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol index 9d4da7fb4..90a5ad920 100644 --- a/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol +++ b/tests/forge/regression/ERC20Pool/RegressionTestLiquidationERC20Pool.t.sol @@ -726,7 +726,6 @@ contract RegressionTestLiquidationWith10BucketsERC20Pool is LiquidationERC20Pool } - contract RegressionTestLiquidationWith20BucketsERC20Pool is LiquidationERC20PoolInvariants { function setUp() public override { @@ -2166,8 +2165,8 @@ contract RegressionTestReserveEvmRevertERC720Pool is LiquidationERC20PoolInvaria invariant_auction(); } } -contract RegressionTestLiquidationWith18QuotePrecision4CollateralPrecisionERC20Pool is LiquidationERC20PoolInvariants { +contract RegressionTestLiquidationWith18QuotePrecision4CollateralPrecisionERC20Pool is LiquidationERC20PoolInvariants { function setUp() public override { vm.setEnv("QUOTE_PRECISION", "18"); vm.setEnv("COLLATERAL_PRECISION", "4"); @@ -2193,7 +2192,6 @@ contract RegressionTestLiquidationWith18QuotePrecision4CollateralPrecisionERC20P invariant_exchange_rate(); } - } contract RegressionTestLiquidationWith8CollateralPrecisionERC20Pool is LiquidationERC20PoolInvariants { @@ -2207,6 +2205,47 @@ contract RegressionTestLiquidationWith8CollateralPrecisionERC20Pool is Liquidati _liquidationERC20PoolHandler.kickAuction(0, 17104183949941796511, 0, 280417724462859438244277310225109843561163957492078708458152152913172346); _liquidationERC20PoolHandler.pledgeCollateral(0, 140265038788604003138859102577, 115792089237316195423570985008687907853269984665640564039457584007913129639932); _liquidationERC20PoolHandler.bucketTake(5683872789780248582962257270041, 1, true, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + + invariant_exchange_rate(); + } +} + +contract RegressionTestLiquidationWith12QuotePrecisionERC20Pool is LiquidationERC20PoolInvariants { + function setUp() public override { + vm.setEnv("QUOTE_PRECISION", "12"); + vm.setEnv("COLLATERAL_PRECISION", "18"); + super.setUp(); + } + + /** + Test was failing with underflow. Resolved by invariant improvements in PR#955. + */ + function test_regression_take_exchange_rate_underflow() external { + _liquidationERC20PoolHandler.pullCollateral(1, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639934); + _liquidationERC20PoolHandler.transferLps(115792089237316195423570985008687907853269984665640564039457584007913129639932, 45909730277988842415738220537184944537676, 1, 0, 0); + _liquidationERC20PoolHandler.kickAuction(70010871234460820744715912936890564712867991293425383626279454116593850533, 6499767, 28762655686049589541294942431851230420669838142, 1571345); + _liquidationERC20PoolHandler.addQuoteToken(181090242960530, 2377505175853220826817239127143875084418686811649475368310406086770995769749, 115792089237316195423570985008687907853269984665640564039457584007913129639932, 72033836997607978984292992820571); + _liquidationERC20PoolHandler.withdrawBonds(695237110902130656531864435588814770662540280753085713853371273119165032, 76187813332501807831094303, 12572696008628451448752492); + _liquidationERC20PoolHandler.transferLps(115792089237316195423570985008687907853269984665640564039457584007913129639935, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 1, 2, 9); + _liquidationERC20PoolHandler.kickAuction(1999999999999999999999043403500806748920639352, 3061195076792591263023058803418546501128, 2379220920797631821002222390458479008558342658478194460908722057821, 31903477196625138712736675); + _liquidationERC20PoolHandler.takeAuction(2, 885557492487161046, 1558101439297927368671261, 1292998037045564783449417757876861668872); + invariant_exchange_rate(); } + + /* + Test was failing because invariant logic for interest accrual was using the pending inflator to calculate HTP. + Fixed by calculating HTP using current pool inflator. + */ + function test_regression_failure_deposits_on_kick_1() external { + _liquidationERC20PoolHandler.drawDebt(2, 3221259065514816790487893458767898964, 4116413047421407597131232320880820919452009); + _liquidationERC20PoolHandler.withdrawBonds(1011868801812554352, 787959216853107061817696631727, 787949941098203131552111773821); + _liquidationERC20PoolHandler.lenderKickAuction(1013350938108023449, 709545743875727362579966764062968642140163108918930414591019589180725257, 1000019286889406901); + _liquidationERC20PoolHandler.pledgeCollateral(702496096288315654151051035260624996909623141681685150581265170070799900, 1025766506493781142223686516002, 1882017544514540473); + _liquidationERC20PoolHandler.addQuoteToken(184116457409845008802273399124418717054, 425420151153612354346298303754178903917488200526, 1524671197004160260571450442257224437845065293837405292129734683, 18328493294); + _liquidationERC20PoolHandler.pledgeCollateral(4184073188804616272013253095810669088604050280846044378968594414041510976844, 15476914321184942485933234133477, 999999999999999999999999999999999999999962315); + _liquidationERC20PoolHandler.kickAuction(2748385666284590326694, 1985130059088839548857545717, 2650077542301436190503272880334, 962354226098822); + + invariant_fenwick(); + } } \ No newline at end of file diff --git a/tests/forge/regression/ERC721Pool/RegressionTestLiquidationERC721Pool.t.sol b/tests/forge/regression/ERC721Pool/RegressionTestLiquidationERC721Pool.t.sol index aeb17e536..6cd0cba8b 100644 --- a/tests/forge/regression/ERC721Pool/RegressionTestLiquidationERC721Pool.t.sol +++ b/tests/forge/regression/ERC721Pool/RegressionTestLiquidationERC721Pool.t.sol @@ -148,6 +148,90 @@ contract RegressionTestLiquidationERC721Pool is LiquidationERC721PoolInvariants invariant_auction(); } + /* + Test was failing because invariant logic for interest accrual was using the pending inflator to calculate HTP. + Fixed by calculating HTP using current pool inflator. + */ + function test_regression_deposit_failure_on_kick() external { + _liquidationERC721PoolHandler.withdrawBonds(10151, 18965, 1020000000000000001); + _liquidationERC721PoolHandler.removeQuoteToken(365303, 507275043721539544302939, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 125911375); + _liquidationERC721PoolHandler.pledgeCollateral(3, 9996808070360292113771437527343998095987, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.pledgeCollateral(6307, 872, 341); + _liquidationERC721PoolHandler.removeCollateral(6605, 20566, 24086, 24750); + _liquidationERC721PoolHandler.settleAuction(3, 6680755863680591634516978573228506572678958484447741053105113661241, 9834485764842002831925334809916199166633064298755379483552181801112594843616, 50703884214635118721624182290913); + _liquidationERC721PoolHandler.kickAuction(39057024788508847549173945341071998484914610296608937202299085565969969640252, 3235, 10804, 8417); + _liquidationERC721PoolHandler.settleAuction(115792089237316195423570985008687907853269984665640564039457584007913129639932, 123359, 65135767502483322888879658363255802111200969216152288244494, 3728304808243239040071486687027857); + _liquidationERC721PoolHandler.settleAuction(115792089237316195423570985008687907853269984665640564039457584007913129639935, 1148335230970937770228357354206417397254312, 1035898490921891589378470660981278329641, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.mergeCollateral(115792089237316195423570985008687907853269984665640564039457584007913129639932, 250816888133993755286503823043955376630422416601097); + _liquidationERC721PoolHandler.drawDebt(11, 115792089237316195423570985008687907853269984665640564039457584007913129639932, 3); + _liquidationERC721PoolHandler.transferLps(15164, 3320, 1806, 24015, 76658); + _liquidationERC721PoolHandler.addQuoteToken(5042, 26511057352925151874817900429276281706694346584662189088043467429524323658544, 3995, 110349606679412691172957834289542550319383271247755660854362242977991410020434); + _liquidationERC721PoolHandler.mergeCollateral(2501, 5506); + _liquidationERC721PoolHandler.pullCollateral(22041, 23031, 10131); + _liquidationERC721PoolHandler.settleAuction(11839, 4259, 19703, 9693024030714756568067279153903244326330763878692170628927831827550217958896); + _liquidationERC721PoolHandler.transferLps(511931736016295037753186721368463022982877302778388892623354192, 553696476731907182347014230710049406932822682801485701715456718968074388, 115792089237316195423570985008687907853269984665640564039457584007913129639935, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639934); + _liquidationERC721PoolHandler.addCollateral(55413914203880181617863896666300790188000185525332589491462336155216289396896, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 133233428933732810679239771747092881, 2); + _liquidationERC721PoolHandler.transferLps(1823912203085512184641541, 1882264261310549184763878438481473378, 9390339394047767, 4414974500083230285889258322251947670680166129266357160851208, 1454257427256505668793722804826066321244748623461395675065095); + _liquidationERC721PoolHandler.transferLps(3497, 373702251020986977207790889868085050901394374962, 49090186810688179261078073503577808280209137270570567486019912342355983157986, 869, 21668); + _liquidationERC721PoolHandler.pullCollateral(3, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.pullCollateral(11, 99036894565123307346187197492593689057928629848983777222631, 1); + _liquidationERC721PoolHandler.moveQuoteToken(3200015543879080977978631399859206700164459691074831432, 546920627716800193603380200657873, 955442091705193936, 262774850139282107595856507261543741866193, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.pledgeCollateral(2079081365371439630533360595904787989338722, 20975265286992043997481427078, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + _liquidationERC721PoolHandler.drawDebt(1469926278681390766507302132782139948879666057661270, 848317814986, 0); + _liquidationERC721PoolHandler.stampLoan(2306, 16052); + _liquidationERC721PoolHandler.removeQuoteToken(78144, 28935746538934562635267948776175440970003463695910303326678356370008353344387, 19150, 3660); + _liquidationERC721PoolHandler.bucketTake(25320, 26511057352925151874817900429276281706694346584662189088043467429524323658502, true, 115040648028213763271245853549043880494636874452181292758191479633142775385701, 13693); + _liquidationERC721PoolHandler.withdrawBonds(12603, 22583, 10741); + _liquidationERC721PoolHandler.moveQuoteToken(13595, 20808, 7027, 12900, 67990265283967347010428190204940206325369423363321040257100631028051732765951); + _liquidationERC721PoolHandler.pullCollateral(2, 2704263492620157737497782640272014567052322021231, 115792089237316195423570985008687907853269984665640564039457584007913129639934); + _liquidationERC721PoolHandler.addCollateral(72954192179059125710500624555767362548334585960590749550312047, 0, 1516245675353177124, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + _liquidationERC721PoolHandler.settleAuction(2564, 13907, 8260, 4116); + _liquidationERC721PoolHandler.settleAuction(2717845938335, 1, 3, 2); + _liquidationERC721PoolHandler.bucketTake(3935425623270109966153362048114416736349485, 182, true, 7459, 2740); + _liquidationERC721PoolHandler.addQuoteToken(274, 3718068959393935372383794679, 92001987806333700856071384682550468910212704266158266358190575554223580054799, 3137); + _liquidationERC721PoolHandler.addCollateral(1449507396, 3719398720937196887342302451, 21266833574923104133284801100447832832056180790662699274815137743018857468926, 15718); + _liquidationERC721PoolHandler.withdrawBonds(2, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.takeAuction(0, 1665125224821926496, 598404668070, 575748930687813014222703790210422220130552545612388557471); + _liquidationERC721PoolHandler.removeCollateral(109484454297595735571924153327555045951160158000225248947426577949447976440767, 189705619361989332678389445740195554268896305433, 14179, 8785); + _liquidationERC721PoolHandler.moveQuoteToken(4642, 110349606679412691172957834289542550319383271247755660854362242977991410020166, 23969, 14269, 57762265046662103); + _liquidationERC721PoolHandler.mergeCollateral(115040648028213763271245853549043880494636874452181292758191479633142775385567, 3010); + _liquidationERC721PoolHandler.removeQuoteToken(247752252501017934, 2172864402628579596102868786712321772713236941993807609250120966089411, 36936808497599283344991293148953976393371727094711283898131892270316603, 23329414938600567202790202035023442036276955684083276597); + _liquidationERC721PoolHandler.kickAuction(13371, 20763, 2195, 706553361502694834509667647); + _liquidationERC721PoolHandler.repayDebt(117008833284489603970636493757855586386746279468790394, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + _liquidationERC721PoolHandler.takeAuction(69262802403772644744922008717209538173404218648276454739580932, 136864923250953306899532527369597003355144806891657, 311896552325518511587323776648924867793954322205178929, 24140077857493540332049223771915); + _liquidationERC721PoolHandler.repayDebt(1305, 7996, 3113774100); + _liquidationERC721PoolHandler.mergeCollateral(86240864503547464300898056724575762995699014, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + _liquidationERC721PoolHandler.bucketTake(1, 2256377999112351740720, false, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639934); + _liquidationERC721PoolHandler.mergeCollateral(6882672892165481254938378795088299568615165783590916, 3); + _liquidationERC721PoolHandler.takeAuction(22498, 5674, 103942114792467962182600111834022925436783569985540614801358664111080265919968, 110349606679412691172957834289542550319383271247755660854362242977991410020593); + _liquidationERC721PoolHandler.repayDebt(5667530734404109228751125561212187329593970104182840261102550845737813833162, 1, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.lenderKickAuction(379411238723978665356778891480391108537792610866, 11247, 369); + _liquidationERC721PoolHandler.mergeCollateral(13935, 6094); + _liquidationERC721PoolHandler.kickAuction(110349606679412691172957834289542550319383271247755660854362242977991410021035, 11393, 3262, 92627268634462374139813757911566025023182692124064317657466656153466661777012); + _liquidationERC721PoolHandler.mergeCollateral(1000158904577156016, 15736); + _liquidationERC721PoolHandler.transferLps(52341347409429374, 600049113027082824983025770417509503093832355143140652853, 114, 3, 3509926951427136102353881364614470); + _liquidationERC721PoolHandler.takeAuction(3, 680404348027311669085825735134827003130, 1681, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + _liquidationERC721PoolHandler.mergeCollateral(18015, 56344); + _liquidationERC721PoolHandler.mergeCollateral(4740, 23678); + _liquidationERC721PoolHandler.pullCollateral(1172558782393486269570, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 51905830384025996195135138815400656860412787804619267321385601445544560951011); + _liquidationERC721PoolHandler.lenderKickAuction(194590724822592229762843737684685371738401106811386487583089, 2, 3); + _liquidationERC721PoolHandler.addCollateral(2, 1777179064050624845780215695583500702303797880787696711805104433662670736988, 1117521870440522256110836023810334082747147037107534, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.failed(); + _liquidationERC721PoolHandler.takeAuction(2997657514669928355520715518098550540193746441521768370, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 30386800514428768267400850843350326025203372485968485472638487922845873361095, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.addQuoteToken(604145652791249977744, 3205952, 3, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.kickAuction(3, 12132, 6, 8211904554); + _liquidationERC721PoolHandler.mergeCollateral(59288, 15111); + _liquidationERC721PoolHandler.pullCollateral(115792089237316195423570985008687907853269984665640564039457584007913129639934, 20732501674893585329351539, 2); + _liquidationERC721PoolHandler.addQuoteToken(44570925613339300411199038756706214321532256605944080591127447210242818008657, 431415980916, 3310, 14373); + _liquidationERC721PoolHandler.takeAuction(115792089237316195423570985008687907853269984665640564039457584007913129639933, 0, 1008879104448547538881, 19764046445139426957555248214479792721787949); + _liquidationERC721PoolHandler.removeCollateral(115792089237316195423570985008687907853269984665640564039457584007913129639934, 21794204538944429217381875706473226113415731944796407, 87554192579501648160234657, 1068738981); + _liquidationERC721PoolHandler.settleAuction(3403886074587726701583543, 1, 74301928586827294, 7730699770853526855555571916078769718916); + _liquidationERC721PoolHandler.pullCollateral(45607232071536911626338559407340181, 24109584780821349367715661292271010615181300475617075667172349023790998778041, 23862); + _liquidationERC721PoolHandler.drawDebt(115792089237316195423570985008687907853269984665640564039457584007913129639935, 1, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.kickAuction(16583, 8591, 92001987806333700856071384682550468910212704266158266358190575554223580054719, 100589673509517359208075717225481249637171673458804355786573416587132293745451); + + invariant_fenwick(); + } } contract RegressionTestLiquidationWith10BucketsERC721Pool is LiquidationERC721PoolInvariants { @@ -278,4 +362,39 @@ contract RegressionTestLiquidationERC721PoolWith12QuotePrecision is LiquidationE invariant_collateral(); } + + /* + Test was failing because invariant logic for interest accrual was using the pending inflator to calculate HTP. + Fixed by calculating HTP using current pool inflator. + */ + function test_regression_failure_deposits_on_kick_2() external { + _liquidationERC721PoolHandler.stampLoan(1101520973663, 340849898329139925023363944281044077674288910705); + _liquidationERC721PoolHandler.bucketTake(38564, 124, true, 6506, 18478); + _liquidationERC721PoolHandler.takeAuction(19698, 12620, 21009, 13986); + _liquidationERC721PoolHandler.pullCollateral(2, 541134438805065095329626877656013320603754476643916851085315771839632, 44); + _liquidationERC721PoolHandler.settleAuction(18445170105345, 27768820298551929539573416057308546294, 1831348234646695979701711193265195624765015, 19806589885779083564708666293665202909299982079894821404); + _liquidationERC721PoolHandler.addQuoteToken(24581781323667122669825371202617098709092025642599709988487142902, 6751483549889384391330009179862741721237430, 2074840997258950548059555849447762, 41004804690541978327690188027); + _liquidationERC721PoolHandler.drawDebt(115792089237316195423570985008687907853269984665640564039457584007913129639932, 1, 4405533926191186669079387132587588); + _liquidationERC721PoolHandler.mergeCollateral(1170, 6791); + _liquidationERC721PoolHandler.lenderKickAuction(261557594648386107050309690843, 2149531941380581, 21398813494550530131524859572390158043429852771132077812453); + _liquidationERC721PoolHandler.pullCollateral(2244700571660709034536706359572610085373763379015793501107352541276, 618, 23239); + _liquidationERC721PoolHandler.addQuoteToken(115792089237316195423570985008687907853269984665640564039457584007913129639932, 16274470882238481041, 6197097, 21823864712259522241570554056911363918960970405); + _liquidationERC721PoolHandler.pullCollateral(2, 7599229, 115792089237316195423570985008687907853269984665640564039457584007913129639932); + _liquidationERC721PoolHandler.stampLoan(856705470883081255239073139418291890062277533648218028719451656473135, 115792089237316195423570985008687907853269984665640564039457584007913129639933); + _liquidationERC721PoolHandler.removeCollateral(584, 703, 78068, 12645); + _liquidationERC721PoolHandler.stampLoan(436561101136594799844207135366044952491661248823909950, 2); + _liquidationERC721PoolHandler.withdrawBonds(4563146251932219736759239506220144592591590156131202302006611845039429, 14350, 3517662147741923340791168219309848016076091); + _liquidationERC721PoolHandler.removeCollateral(25192, 6323, 23521, 16383); + _liquidationERC721PoolHandler.transferLps(20695, 15851, 1517, 3856056065, 20098); + _liquidationERC721PoolHandler.drawDebt(0, 115792089237316195423570985008687907853269984665640564039457584007913129639933, 859480409215446731702270203541533710710020319377429967504251221729934999); + _liquidationERC721PoolHandler.settleAuction(126936323669234570513273085709441059235, 115792089237316195423570985008687907853269984665640564039457584007913129639934, 115792089237316195423570985008687907853269984665640564039457584007913129639932, 8248932491597069592573032352920451438269307575316205933141289543353452443); + _liquidationERC721PoolHandler.failed(); + _liquidationERC721PoolHandler.addQuoteToken(62, 16565086470505342429058968, 3, 0); + _liquidationERC721PoolHandler.pullCollateral(0, 1514221, 2); + _liquidationERC721PoolHandler.pledgeCollateral(0, 35924561148819755256489348713910568088, 90016113586623091009188116577000963562088529923191612303619720343); + _liquidationERC721PoolHandler.settleAuction(2400, 19226, 70782602156620013982052507478745924339327460599400232115223540562545500139749, 9354); + _liquidationERC721PoolHandler.kickAuction(115792089237316195423570985008687907853269984665640564039457584007913129639934, 1199072574072325921531799195390860, 295013, 347551799326168676289233799); + + invariant_fenwick(); + } } \ No newline at end of file