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

Update last total assets in _setCap #338

Merged
merged 12 commits into from
Dec 28, 2023
Merged
2 changes: 2 additions & 0 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

marketConfig.enabled = true;

_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(_marketParams(id), 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 {
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading