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

Conversation

Jean-Grimal
Copy link
Contributor

src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Outdated Show resolved Hide resolved
@@ -779,6 +781,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph
}

marketConfig.enabled = true;

_updateLastTotalAssets(totalAssets());
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
_updateLastTotalAssets(totalAssets());
_updateLastTotalAssets(newTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));

And we could expect _setCap to have MarketParams as input (and in turn expect acceptCap) to have MarketParams as input

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that it changes the ABI, so we must notify @julien-devatom if we do it

Copy link
Contributor Author

@Jean-Grimal Jean-Grimal Dec 7, 2023

Choose a reason for hiding this comment

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

I feel like _updateLastTotalAssets(totalAssets()); does the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we could just not accrue fees and only have _updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this))), this might be the better option no ?

And we could use idToMarketParams so no need for _setCap to have MarketParams

Copy link
Contributor

@Rubilmax Rubilmax Dec 7, 2023

Choose a reason for hiding this comment

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

This would symmetrical to update withdraw queue indeed 👍

However I push for having MarketParams as input because we can afford to have it in this context, whereas we can't in ERC4626 functions (and is this the reason we use idToMarketParams)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So Do I add MarketParams as input for acceptCap and submitMarketRemoval ? Or do I just change the Id input by MarketParams ?

Copy link
Contributor

Choose a reason for hiding this comment

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

To me the id can always be calculated given the market params so i think only the market params is necessary
I'd wait for others' thoughts beforehand thoug

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that it changes the ABI, so we must notify @julien-devatom if we do it

Not only me, all the integrators !! It's also critical for integrators (can break everything)

Copy link
Contributor

@MerlinEgalite MerlinEgalite Dec 8, 2023

Choose a reason for hiding this comment

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

What do you mean by "can break everything", the fee accounting you mean?

Comment on lines +783 to +784
MarketParams memory marketParams = MORPHO.idToMarketParams(id);
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
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
MarketParams memory marketParams = MORPHO.idToMarketParams(id);
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this)));
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

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

@@ -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 {

Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

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

Agree with the @Rubilmax's suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants