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

Remove accrueInterest #405

Merged
merged 2 commits into from
Aug 22, 2023
Merged
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
8 changes: 0 additions & 8 deletions src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,6 @@ contract Morpho is IMorpho {

/* INTEREST MANAGEMENT */

/// @inheritdoc IMorpho
function accrueInterest(MarketParams memory marketParams) external {
Id id = marketParams.id();
require(market[id].lastUpdate != 0, ErrorsLib.MARKET_NOT_CREATED);

_accrueInterest(marketParams, id);
}

/// @dev Accrues interest for market `marketParams`.
/// @dev Assumes the given `marketParams` and `id` match.
function _accrueInterest(MarketParams memory marketParams, Id id) internal {
Expand Down
6 changes: 2 additions & 4 deletions src/interfaces/IMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct MarketParams {
uint256 lltv;
}

/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest accrual.
/// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest
/// accrual.
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
struct User {
uint256 supplyShares;
uint128 borrowShares;
Expand Down Expand Up @@ -243,9 +244,6 @@ interface IMorpho {
/// @param signature The signature.
function setAuthorizationWithSig(Authorization calldata authorization, Signature calldata signature) external;

/// @notice Accrues interest for `market`.
function accrueInterest(MarketParams memory marketParams) external;

/// @notice Returns the data stored on the different `slots`.
function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory res);
}
6 changes: 6 additions & 0 deletions test/forge/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ contract BaseTest is Test {
UtilsLib.min(MAX_LIQUIDATION_INCENTIVE_FACTOR, WAD.wDivDown(WAD - LIQUIDATION_CURSOR.wMulDown(WAD - lltv)));
}

function _accrueInterest() internal {
collateralToken.setBalance(address(this), 1);
morpho.supplyCollateral(market, 1, address(this), hex"");
morpho.withdrawCollateral(market, 1, address(this), address(10));
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
}

function neq(MarketParams memory a, MarketParams memory b) internal pure returns (bool) {
return (Id.unwrap(a.id()) != Id.unwrap(b.id()));
}
Expand Down
21 changes: 10 additions & 11 deletions test/forge/integration/TestIntegrationAccrueInterest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ contract IntegrationAccrueInterestTest is BaseTest {
using MorphoLib for Morpho;
using SharesMathLib for uint256;

function testAccrueInterestMarketNotCreated(MarketParams memory marketParamsFuzz) public {
vm.assume(neq(market, marketParamsFuzz));

vm.expectRevert(bytes(ErrorsLib.MARKET_NOT_CREATED));
morpho.accrueInterest(marketParamsFuzz);
}

function testAccrueInterestNoTimeElapsed(uint256 amountSupplied, uint256 amountBorrowed) public {
uint256 collateralPrice = IOracle(market.oracle).price();
uint256 amountCollateral;
Expand All @@ -39,7 +32,7 @@ contract IntegrationAccrueInterestTest is BaseTest {
uint256 totalSupplyBeforeAccrued = morpho.totalSupplyAssets(id);
uint256 totalSupplySharesBeforeAccrued = morpho.totalSupplyShares(id);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(morpho.totalBorrowAssets(id), totalBorrowBeforeAccrued, "total borrow");
assertEq(morpho.totalSupplyAssets(id), totalSupplyBeforeAccrued, "total supply");
Expand All @@ -66,7 +59,7 @@ contract IntegrationAccrueInterestTest is BaseTest {
uint256 totalSupplyBeforeAccrued = morpho.totalSupplyAssets(id);
uint256 totalSupplySharesBeforeAccrued = morpho.totalSupplyShares(id);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(morpho.totalBorrowAssets(id), totalBorrowBeforeAccrued, "total borrow");
assertEq(morpho.totalSupplyAssets(id), totalSupplyBeforeAccrued, "total supply");
Expand Down Expand Up @@ -108,9 +101,12 @@ contract IntegrationAccrueInterestTest is BaseTest {
uint256 totalSupplySharesBeforeAccrued = morpho.totalSupplyShares(id);
uint256 expectedAccruedInterest = totalBorrowBeforeAccrued.wMulDown(borrowRate.wTaylorCompounded(timeElapsed));

collateralToken.setBalance(address(this), 1);
morpho.supplyCollateral(market, 1, address(this), hex"");
vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.AccrueInterest(id, borrowRate, expectedAccruedInterest, 0);
morpho.accrueInterest(market);
// Accrues interest.
morpho.withdrawCollateral(market, 1, address(this), address(this));

assertEq(morpho.totalBorrowAssets(id), totalBorrowBeforeAccrued + expectedAccruedInterest, "total borrow");
assertEq(morpho.totalSupplyAssets(id), totalSupplyBeforeAccrued + expectedAccruedInterest, "total supply");
Expand Down Expand Up @@ -176,9 +172,12 @@ contract IntegrationAccrueInterestTest is BaseTest {
params.totalSupplySharesBeforeAccrued
);

collateralToken.setBalance(address(this), 1);
morpho.supplyCollateral(market, 1, address(this), hex"");
vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.AccrueInterest(id, params.borrowRate, params.expectedAccruedInterest, params.feeShares);
morpho.accrueInterest(market);
// Accrues interest.
morpho.withdrawCollateral(market, 1, address(this), address(this));

assertEq(
morpho.totalSupplyAssets(id),
Expand Down
12 changes: 6 additions & 6 deletions test/forge/periphery/MorphoBalancesLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract MorphoBalancesLibTest is BaseTest {
uint256 virtualTotalBorrowShares
) = morpho.expectedMarketBalances(market);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(virtualTotalSupply, morpho.totalSupplyAssets(id), "total supply");
assertEq(virtualTotalBorrow, morpho.totalBorrowAssets(id), "total borrow");
Expand All @@ -38,7 +38,7 @@ contract MorphoBalancesLibTest is BaseTest {

uint256 expectedTotalSupply = morpho.expectedTotalSupply(market);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(expectedTotalSupply, morpho.totalSupplyAssets(id));
}
Expand All @@ -50,7 +50,7 @@ contract MorphoBalancesLibTest is BaseTest {

uint256 expectedTotalBorrow = morpho.expectedTotalBorrow(market);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(expectedTotalBorrow, morpho.totalBorrowAssets(id));
}
Expand All @@ -65,7 +65,7 @@ contract MorphoBalancesLibTest is BaseTest {

uint256 expectedTotalSupplyShares = morpho.expectedTotalSupplyShares(market);

morpho.accrueInterest(market);
_accrueInterest();

assertEq(expectedTotalSupplyShares, morpho.totalSupplyShares(id));
}
Expand All @@ -77,7 +77,7 @@ contract MorphoBalancesLibTest is BaseTest {

uint256 expectedSupplyBalance = morpho.expectedSupplyBalance(market, address(this));

morpho.accrueInterest(market);
_accrueInterest();

uint256 actualSupplyBalance = morpho.supplyShares(id, address(this)).toAssetsDown(
morpho.totalSupplyAssets(id), morpho.totalSupplyShares(id)
Expand All @@ -93,7 +93,7 @@ contract MorphoBalancesLibTest is BaseTest {

uint256 expectedBorrowBalance = morpho.expectedBorrowBalance(market, address(this));

morpho.accrueInterest(market);
_accrueInterest();

uint256 actualBorrowBalance = morpho.borrowShares(id, address(this)).toAssetsUp(
morpho.totalBorrowAssets(id), morpho.totalBorrowShares(id)
Expand Down