Skip to content

Commit

Permalink
Implement comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pakim249CAL committed Dec 12, 2022
1 parent 3f2d0b9 commit 303288c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/compound/MorphoGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ abstract contract MorphoGovernance is MorphoUtils {

/// ERRORS ///

/// @notice Thrown when the creation of a market failed on Compound and kicks back Compound error code.
error MarketCreationFailedOnCompound(uint256 errorCode);

/// @notice Thrown when the input is above the max basis points value (100%).
error ExceedsMaxBasisPoints();

Expand All @@ -124,9 +127,6 @@ abstract contract MorphoGovernance is MorphoUtils {
/// @notice Thrown when the address is the zero address.
error ZeroAddress();

/// @notice Throws back Compound errors.
error CompoundError(uint256 errorCode);

/// UPGRADE ///

/// @notice Initializes the Morpho contract.
Expand Down Expand Up @@ -440,7 +440,7 @@ abstract contract MorphoGovernance is MorphoUtils {
address[] memory marketToEnter = new address[](1);
marketToEnter[0] = _poolToken;
uint256[] memory results = comptroller.enterMarkets(marketToEnter);
if (results[0] != 0) revert CompoundError(results[0]);
if (results[0] != 0) revert MarketCreationFailedOnCompound(results[0]);

// Same initial index as Compound.
uint256 initialIndex;
Expand Down
23 changes: 16 additions & 7 deletions src/compound/PositionsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
/// @notice Thrown when the amount repaid during the liquidation is above what is allowed to be repaid.
error AmountAboveWhatAllowedToRepay();

/// @notice Thrown when the borrow on Compound failed and throws back the Compound error code.
error BorrowOnCompoundFailed(uint256 errorCode);

/// @notice Thrown when the redeem on Compound failed and throws back the Compound error code.
error RedeemOnCompoundFailed(uint256 errorCode);

/// @notice Thrown when the repay on Compound failed and throws back the Compound error code.
error RepayOnCompoundFailed(uint256 errorCode);

/// @notice Thrown when the mint on Compound failed and throws back the Compound error code.
error MintOnCompoundFailed(uint256 errorCode);

/// @notice Thrown when user is not a member of the market.
error UserNotMemberOfMarket();

Expand Down Expand Up @@ -167,9 +179,6 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
/// @notice Thrown when someone tries to liquidate but the liquidation with this asset as debt is paused.
error LiquidateBorrowIsPaused();

/// @notice Throws back Compound errors.
error CompoundError(uint256 errorCode);

/// STRUCTS ///

// Struct to avoid stack too deep.
Expand Down Expand Up @@ -918,7 +927,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
} else {
_underlyingToken.safeApprove(_poolToken, _amount);
uint256 errorCode = ICToken(_poolToken).mint(_amount);
if (errorCode != 0) revert CompoundError(errorCode);
if (errorCode != 0) revert MintOnCompoundFailed(errorCode);
}
}

Expand All @@ -930,7 +939,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
_amount = CompoundMath.min(ICToken(_poolToken).balanceOfUnderlying(address(this)), _amount);

uint256 errorCode = ICToken(_poolToken).redeemUnderlying(_amount);
if (errorCode != 0) revert CompoundError(errorCode);
if (errorCode != 0) revert RedeemOnCompoundFailed(errorCode);

if (_poolToken == cEth) IWETH(address(wEth)).deposit{value: _amount}(); // Turn the ETH received in wETH.
}
Expand All @@ -940,7 +949,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
/// @param _amount The amount of token (in underlying).
function _borrowFromPool(address _poolToken, uint256 _amount) internal {
uint256 errorCode = ICToken(_poolToken).borrow(_amount);
if (errorCode != 0) revert CompoundError(errorCode);
if (errorCode != 0) revert BorrowOnCompoundFailed(errorCode);

if (_poolToken == cEth) IWETH(address(wEth)).deposit{value: _amount}(); // Turn the ETH received in wETH.
}
Expand All @@ -967,7 +976,7 @@ contract PositionsManager is IPositionsManager, MatchingEngine {
} else {
_underlyingToken.safeApprove(_poolToken, _amount);
uint256 errorCode = ICToken(_poolToken).repayBorrow(_amount);
if (errorCode != 0) revert CompoundError(errorCode);
if (errorCode != 0) revert RepayOnCompoundFailed(errorCode);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/compound/TestGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract TestGovernance is TestSetup {
function testShouldRevertWhenCreatingMarketWithAnImproperMarket() public {
Types.MarketParameters memory marketParams = Types.MarketParameters(3_333, 0);

hevm.expectRevert(abi.encodeWithSignature("CompoundError(uint256)", 9));
hevm.expectRevert(abi.encodeWithSignature("MarketCreationFailedOnCompound(uint256)", 9));
morpho.createMarket(address(supplier1), marketParams);
}

Expand Down

0 comments on commit 303288c

Please sign in to comment.