Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Dec 7, 2023
1 parent bda9cd6 commit e365952
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,6 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

if (supplyCap > 0) {
if (!marketConfig.enabled) {
_updateLastTotalAssets(_accrueFee());

supplyQueue.push(id);
withdrawQueue.push(id);

Expand All @@ -782,7 +780,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph

marketConfig.enabled = true;

_updateLastTotalAssets(totalAssets());
MarketParams memory marketParams = MORPHO.idToMarketParams(id);
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
}

marketConfig.removableAt = 0;
Expand Down
36 changes: 36 additions & 0 deletions test/forge/MarketTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {SafeCast} from "../../lib/openzeppelin-contracts/contracts/utils/math/Sa
import "./helpers/IntegrationTest.sol";

contract MarketTest is IntegrationTest {
using MathLib for uint256;
using MarketParamsLib for MarketParams;
using MorphoLib for IMorpho;

Expand Down Expand Up @@ -279,4 +280,39 @@ contract MarketTest is IntegrationTest {
);
vault.updateWithdrawQueue(indexes);
}

function testenableMarketWithLiquidity(uint256 deposited, uint256 additionalSupply, uint256 blocks) public {
deposited = bound(deposited, MIN_TEST_ASSETS, MAX_TEST_ASSETS);
additionalSupply = bound(additionalSupply, MIN_TEST_ASSETS, MAX_TEST_ASSETS);
blocks = _boundBlocks(blocks);

Id[] memory supplyQueue = new Id[](1);
supplyQueue[0] = allMarkets[0].id();

_setCap(allMarkets[0], deposited);

vm.prank(ALLOCATOR);
vault.setSupplyQueue(supplyQueue);

loanToken.setBalance(SUPPLIER, deposited + additionalSupply);

vm.startPrank(SUPPLIER);
vault.deposit(deposited, ONBEHALF);
morpho.supply(allMarkets[3], additionalSupply, 0, address(vault), hex"");
vm.stopPrank();

uint256 collateral = uint256(MAX_TEST_ASSETS).wDivUp(allMarkets[0].lltv);
collateralToken.setBalance(BORROWER, collateral);

vm.startPrank(BORROWER);
morpho.supplyCollateral(allMarkets[0], collateral, BORROWER, hex"");
morpho.borrow(allMarkets[0], deposited, 0, BORROWER, BORROWER);
vm.stopPrank();

_forward(blocks);

_setCap(allMarkets[3], CAP);

assertEq(vault.lastTotalAssets(), deposited + additionalSupply);
}
}

0 comments on commit e365952

Please sign in to comment.