Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sherlock 139.md #579

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libraries/external/Auctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,8 @@ library Auctions {
vars.t0RepayAmount = Maths.wdiv(vars.scaledQuoteTokenAmount, inflator_);
vars.unscaledQuoteTokenAmount = vars.unscaledDeposit;

vars.scaledQuoteTokenAmount = Maths.wmul(vars.collateralAmount, vars.auctionPrice);

} else if (vars.borrowerDebt <= borrowerCollateralValue) {
// borrower debt is constraining factor
vars.collateralAmount = _roundToScale(Maths.wdiv(vars.borrowerDebt, borrowerPrice), collateralScale_);
Expand Down
2 changes: 1 addition & 1 deletion tests/forge/ERC20Pool/ERC20PoolLiquidationsArbTake.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ contract ERC20PoolLiquidationsArbTakeTest is ERC20HelperContract {
kicker: _lender,
index: _i1505_26,
collateralArbed: 0.731315193857015473 * 1e18,
quoteTokenAmount: 15.000000000000000000 * 1e18,
quoteTokenAmount: 14.99999999999999999 * 1e18,
bondChange: 0.15 * 1e18,
isReward: false,
lpAwardTaker: 1_085.822235391290531116686016658 * 1e27,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ contract ERC20PoolLiquidationsDepositTakeTest is ERC20HelperContract {
kicker: _lender,
index: _i1505_26,
collateralArbed: 0.009965031187761219 * 1e18,
quoteTokenAmount: 15.0 * 1e18,
quoteTokenAmount: 14.999999999999999995 * 1e18,
bondChange: 0.15 * 1e18,
isReward: false,
lpAwardTaker: 0,
Expand Down
38 changes: 27 additions & 11 deletions tests/forge/ERC721Pool/ERC721PoolCollateral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,22 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {
})
);

// force an interest accumulation to assert bucket with interest
_addLiquidity({
from: _lender,
amount: 0 * 1e18,
index: 7000,
newLup: 99836282890,
lpAward: 0 * 1e27
});
_assertBucket({
index: 3060,
lpBalance: 20.000000000000000000 * 1e27,
collateral: 0.0000000000000000000 * 1e18,
deposit: 20.010216420146293860 * 1e18,
exchangeRate: 1.000510821007314693000000000 * 1e27
});

// Before depositTake: NFTs pledged by liquidated borrower are owned by the borrower in the pool
assertEq(_collateral.ownerOf(1), address(_pool));
assertEq(_collateral.ownerOf(3), address(_pool));
Expand All @@ -634,18 +650,18 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {

_assertBucket({
index: 3060,
lpBalance: 20.2 * 1e27,
lpBalance: 20.202020202020202022 * 1e27,
collateral: 0.085430491711717314 * 1e18,
deposit: 0,
exchangeRate: 1.000610882095524250072170475 * 1e27
exchangeRate: 1.000510821007314697558117795 * 1e27
});

_assertBucket({
index: 3061,
lpBalance: 20.2 * 1e27,
lpBalance: 20.202020202020202019 * 1e27,
collateral: 0.085857644170275899 * 1e18,
deposit: 0,
exchangeRate: 1.000610882095524239992886155 * 1e27
exchangeRate: 1.000510821007314687628417260 * 1e27
});

_assertBucket({
Expand Down Expand Up @@ -682,7 +698,7 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {
encumberedCollateral: 4407944209.541175956055268556 * 1e18,
poolDebt: 440.072765067090279852 * 1e18,
actualUtilization: 0,
targetUtilization: 3_123_578_486.651416548727612650 * 1e18,
targetUtilization: 2_996_091_127.870826153174895975 * 1e18,
minDebtAmount: 0,
loans: 0,
maxBorrower: address(0),
Expand Down Expand Up @@ -793,22 +809,22 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {

_assertBucket({
index: 3060,
lpBalance: 20.2 * 1e27,
lpBalance: 20.202020202020202022 * 1e27,
collateral: 0.085430491711717314 * 1e18,
deposit: 0,
exchangeRate: 1.000610882095524250072170475 * 1e27
exchangeRate: 1.000510821007314697558117795 * 1e27
});
_assertBucket({
index: 3069,
lpBalance: 20.2 * 1e27,
lpBalance: 20.20202020202020202 * 1e27,
collateral: 0.089352655062849951 * 1e18,
deposit: 0,
exchangeRate: 1.000610882095524241676916623 * 1e27
exchangeRate: 1.000510821007314689262754039 * 1e27
});
_assertLenderLpBalance({
lender: _lender,
index: 3069,
lpBalance: 20.2 * 1e27,
lpBalance: 20.20202020202020202 * 1e27,
depositTime: _startTime + 10000 days + 32 hours
});
_assertBucket({
Expand Down Expand Up @@ -989,7 +1005,7 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {
encumberedCollateral: 0,
poolDebt: 0,
actualUtilization: 0,
targetUtilization: 3123578486.651416548727612650 * 1e18,
targetUtilization: 2_996_091_127.870826153174895975 * 1e18,
minDebtAmount: 0,
loans: 0,
maxBorrower: address(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ contract ERC721PoolLiquidationsDepositTakeTest is ERC721HelperContract {
kicker: _lender,
index: _i1505_26,
collateralArbed: 0.009965031187761219 * 1e18,
quoteTokenAmount: 15.0 * 1e18,
quoteTokenAmount: 14.999999999999999995 * 1e18,
bondChange: 0.15 * 1e18,
isReward: false,
lpAwardTaker: 0,
Expand Down
66 changes: 33 additions & 33 deletions tests/forge/ERC721Pool/ERC721PoolLiquidationsSettleAuction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBorrower({
borrower: _borrower,
Expand Down Expand Up @@ -399,10 +399,10 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBucket({
index: 2501,
Expand Down Expand Up @@ -490,19 +490,19 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
kicker: _lender,
index: 2500,
collateralArbed: 1.848006454703595366 * 1e18,
quoteTokenAmount: 4_998.040748687334744778 * 1e18,
bondChange: 1_499.412224606200423433 * 1e18,
quoteTokenAmount: 7_140.058212410478208121 * 1e18,
bondChange: 2_142.017463723143462436 * 1e18,
isReward: true,
lpAwardTaker: 0,
lpAwardKicker: 1_499.134615384615384200000000000 * 1e27
lpAwardKicker: 2_141.620879120879120674 * 1e27
});

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBorrower({
borrower: _borrower,
Expand Down Expand Up @@ -573,10 +573,10 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBucket({
index: 6113,
Expand Down Expand Up @@ -664,19 +664,19 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
kicker: _lender,
index: 2500,
collateralArbed: 1.848006454703595366 * 1e18,
quoteTokenAmount: 4_998.040748687334744778 * 1e18,
bondChange: 1_499.412224606200423433 * 1e18,
quoteTokenAmount: 7_140.058212410478208121 * 1e18,
bondChange: 2_142.017463723143462436 * 1e18,
isReward: true,
lpAwardTaker: 0,
lpAwardKicker: 1_499.134615384615384200000000000 * 1e27
lpAwardKicker: 2_141.620879120879120674 * 1e27
});

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBorrower({
borrower: _borrower,
Expand Down Expand Up @@ -739,10 +739,10 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {

_assertBucket({
index: 2500,
lpBalance: 6_496.2499999999999982 * 1e27,
lpBalance: 7_138.736263736263734674 * 1e27,
collateral: 1.848006454703595366 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414485129597 * 1e27
exchangeRate: 1.000185179648802797127066481 * 1e27
});
_assertBucket({
index: 6113,
Expand Down Expand Up @@ -826,8 +826,8 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
kicker: _lender,
index: 2000,
collateralArbed: 0.021378186081598093 * 1e18,
quoteTokenAmount: 1_000 * 1e18,
bondChange: 300 * 1e18,
quoteTokenAmount: 999.9999999999999908 * 1e18,
bondChange: 299.99999999999999724 * 1e18,
isReward: false,
lpAwardTaker: 0,
lpAwardKicker: 0
Expand Down Expand Up @@ -858,7 +858,7 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
from: _lender,
borrower: _borrower,
maxCollateral: 1,
bondChange: 1_201.442307692307693000 * 1e18,
bondChange: 1_201.442307692307695760 * 1e18,
givenAmount: 4_422.207326928504959735 * 1e18,
collateralTaken: 0.286141493566424944 * 1e18,
isReward: false
Expand Down Expand Up @@ -994,19 +994,19 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
kicker: _lender,
index: 2502,
collateralArbed: 0.747044074730990508 * 1e18,
quoteTokenAmount: 2_000.370359297605594000 * 1e18,
bondChange: 600.111107789281678200 * 1e18,
quoteTokenAmount: 2_857.671941853722277733 * 1e18,
bondChange: 857.301582556116683320 * 1e18,
isReward: true,
lpAwardTaker: 0,
lpAwardKicker: 600 * 1e27
lpAwardKicker: 857.142857142857143034 * 1e27
});

_assertBucket({
index: 2502,
lpBalance: 2_600 * 1e27,
lpBalance: 2_857.142857142857143034 * 1e27,
collateral: 0.747044074730990508 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414512504812 * 1e27
exchangeRate: 1.000185179648802797144467916 * 1e27
});
_assertBorrower({
borrower: _borrower,
Expand Down Expand Up @@ -1162,19 +1162,19 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
kicker: _lender,
index: 2502,
collateralArbed: 0.747044074730990508 * 1e18,
quoteTokenAmount: 2_000.370359297605594000 * 1e18,
bondChange: 600.111107789281678200 * 1e18,
quoteTokenAmount: 2_857.671941853722277733 * 1e18,
bondChange: 857.301582556116683320 * 1e18,
isReward: true,
lpAwardTaker: 0,
lpAwardKicker: 600 * 1e27
lpAwardKicker: 857.142857142857143034 * 1e27
});

_assertBucket({
index: 2502,
lpBalance: 2_600 * 1e27,
lpBalance: 2_857.142857142857143034 * 1e27,
collateral: 0.747044074730990508 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414512504812 * 1e27
exchangeRate: 1.000185179648802797144467916 * 1e27
});
_assertBorrower({
borrower: _borrower,
Expand Down Expand Up @@ -1245,10 +1245,10 @@ contract ERC721PoolLiquidationsSettleAuctionTest is ERC721HelperContract {
});
_assertBucket({
index: 2502,
lpBalance: 2_600 * 1e27,
lpBalance: 2_857.142857142857143034000000000 * 1e27,
collateral: 0.747044074730990508 * 1e18,
deposit: 0,
exchangeRate: 1.099104593020662414512504812 * 1e27
exchangeRate: 1.000185179648802797144467916 * 1e27
});
_assertBucket({
index: 7388,
Expand Down