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 accept cap #1

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/MetaMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

marketConfig.enabled = true;

MarketParams memory marketParams = MORPHO.idToMarketParams(id);
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
Comment on lines +783 to +784
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MarketParams memory marketParams = MORPHO.idToMarketParams(id);
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(_marketParams(id), address(this)));

Comment on lines +783 to +784
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior implies that no fee is capture when a non-zero supply market is opened
Which is the behavior we want I believe, but may not be canonical to curators

}

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function testenableMarketWithLiquidity(uint256 deposited, uint256 additionalSupply, uint256 blocks) public {
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems innocent, but it's not! Great


_setCap(allMarkets[3], CAP);

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