-
Notifications
You must be signed in to change notification settings - Fork 55
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
fix invariants tests #595
Closed
Closed
fix invariants tests #595
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75e5b5a
ci(invariant): re-enable invariants in CI
Rubilmax 27021e9
test(invariant): re-implement lost invariants
Rubilmax ad6d7b6
test: fix bound utils
Rubilmax 5d5a384
fix(invariant): decrease mine range
Rubilmax c3a3f9b
fix(invariant): decrease max repaid shares
Rubilmax a5b900f
Merge pull request #596 from morpho-org/ci/invariant-no-interest
MathisGD ae79557
Merge remote-tracking branch 'origin/main' into ci/invariant
MathisGD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
import "./BaseMorphoInvariantTest.sol"; | ||
|
||
contract MorphoDynamicInvariantTest is BaseMorphoInvariantTest { | ||
using MathLib for uint256; | ||
using SharesMathLib for uint256; | ||
using MorphoLib for IMorpho; | ||
using MorphoBalancesLib for IMorpho; | ||
using MarketParamsLib for MarketParams; | ||
|
||
uint256 internal immutable MIN_PRICE = ORACLE_PRICE_SCALE / 10; | ||
uint256 internal immutable MAX_PRICE = ORACLE_PRICE_SCALE * 10; | ||
|
||
function setUp() public virtual override { | ||
_weightSelector(this.supplyAssetsOnBehalfNoRevert.selector, 15); | ||
_weightSelector(this.supplySharesOnBehalfNoRevert.selector, 5); | ||
_weightSelector(this.withdrawAssetsOnBehalfNoRevert.selector, 10); | ||
_weightSelector(this.borrowAssetsOnBehalfNoRevert.selector, 15); | ||
_weightSelector(this.repayAssetsOnBehalfNoRevert.selector, 10); | ||
_weightSelector(this.repaySharesOnBehalfNoRevert.selector, 10); | ||
_weightSelector(this.supplyCollateralOnBehalfNoRevert.selector, 15); | ||
_weightSelector(this.withdrawCollateralOnBehalfNoRevert.selector, 10); | ||
_weightSelector(this.liquidateSeizedAssetsNoRevert.selector, 2); | ||
_weightSelector(this.liquidateRepaidSharesNoRevert.selector, 2); | ||
_weightSelector(this.setFeeNoRevert.selector, 1); | ||
_weightSelector(this.setPrice.selector, 5); | ||
_weightSelector(this.mine.selector, 100); | ||
|
||
super.setUp(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont' get why this is put before the weightSelectors, some tests fail.. |
||
} | ||
|
||
/* HANDLERS */ | ||
|
||
function setPrice(uint256 price) external { | ||
price = bound(price, MIN_PRICE, MAX_PRICE); | ||
|
||
oracle.setPrice(price); | ||
} | ||
|
||
/* INVARIANTS */ | ||
|
||
function invariantSupplyShares() public { | ||
address[] memory users = targetSenders(); | ||
|
||
for (uint256 i; i < allMarketParams.length; ++i) { | ||
MarketParams memory _marketParams = allMarketParams[i]; | ||
Id _id = _marketParams.id(); | ||
|
||
uint256 sumSupplyShares = morpho.supplyShares(_id, FEE_RECIPIENT); | ||
for (uint256 j; j < users.length; ++j) { | ||
sumSupplyShares += morpho.supplyShares(_id, users[j]); | ||
} | ||
|
||
assertEq(sumSupplyShares, morpho.totalSupplyShares(_id), vm.toString(_marketParams.lltv)); | ||
} | ||
} | ||
|
||
function invariantBorrowShares() public { | ||
address[] memory users = targetSenders(); | ||
|
||
for (uint256 i; i < allMarketParams.length; ++i) { | ||
MarketParams memory _marketParams = allMarketParams[i]; | ||
Id _id = _marketParams.id(); | ||
|
||
uint256 sumBorrowShares; | ||
for (uint256 j; j < users.length; ++j) { | ||
sumBorrowShares += morpho.borrowShares(_id, users[j]); | ||
} | ||
|
||
assertEq(sumBorrowShares, morpho.totalBorrowShares(_id), vm.toString(_marketParams.lltv)); | ||
} | ||
} | ||
|
||
function invariantTotalSupplyGeTotalBorrow() public { | ||
for (uint256 i; i < allMarketParams.length; ++i) { | ||
MarketParams memory _marketParams = allMarketParams[i]; | ||
Id _id = _marketParams.id(); | ||
|
||
assertGe(morpho.totalSupplyAssets(_id), morpho.totalBorrowAssets(_id)); | ||
} | ||
} | ||
|
||
function invariantMorphoBalance() public { | ||
for (uint256 i; i < allMarketParams.length; ++i) { | ||
MarketParams memory _marketParams = allMarketParams[i]; | ||
Id _id = _marketParams.id(); | ||
|
||
assertGe( | ||
loanToken.balanceOf(address(morpho)) + morpho.totalBorrowAssets(_id), morpho.totalSupplyAssets(_id) | ||
); | ||
} | ||
} | ||
|
||
function invariantBadDebt() public { | ||
address[] memory users = targetSenders(); | ||
|
||
for (uint256 i; i < allMarketParams.length; ++i) { | ||
MarketParams memory _marketParams = allMarketParams[i]; | ||
Id _id = _marketParams.id(); | ||
|
||
for (uint256 j; j < users.length; ++j) { | ||
address user = users[j]; | ||
|
||
if (morpho.collateral(_id, user) == 0) { | ||
assertEq( | ||
morpho.borrowShares(_id, user), | ||
0, | ||
string.concat(vm.toString(_marketParams.lltv), ":", vm.toString(user)) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI was running for 183m before failing, perhaps we should lower these