Skip to content

Commit

Permalink
Merge pull request #458 from morpho-dao/poc/eip712-1
Browse files Browse the repository at this point in the history
refactor EIP712
  • Loading branch information
pakim249CAL committed Feb 6, 2023
2 parents c014d50 + fe7c3ff commit ab8b977
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/MorphoGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract contract MorphoGetters is IMorphoGetters, MorphoInternal {

/// @notice Returns the domain separator of the EIP712.
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return _DOMAIN_SEPARATOR;
return _domainSeparator();
}

/// @notice Returns the e-mode category ID of Morpho on the Aave protocol.
Expand Down
15 changes: 14 additions & 1 deletion src/MorphoInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ abstract contract MorphoInternal is MorphoStorage {

/// INTERNAL ///

/// @dev Dynamically computed to use the root proxy address in a delegate call.
function _domainSeparator() internal view returns (bytes32) {
return keccak256(
abi.encode(
Constants.EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(Constants.EIP712_NAME)),
keccak256(bytes(Constants.EIP712_VERSION)),
block.chainid,
address(this)
)
);
}

/// @dev Creates a new market for the `underlying` token with a given `reserveFactor` (in bps) and a given `p2pIndexCursor` (in bps).
function _createMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal {
if (underlying == address(0)) revert Errors.AddressIsZero();
Expand Down Expand Up @@ -141,7 +154,7 @@ abstract contract MorphoInternal is MorphoStorage {

/// @dev Returns the hash of the EIP712 typed data.
function _hashEIP712TypedData(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked(Constants.EIP712_MSG_PREFIX, _DOMAIN_SEPARATOR, structHash));
return keccak256(abi.encodePacked(Constants.EIP712_MSG_PREFIX, _domainSeparator(), structHash));
}

/// @notice Approves a `manager` to borrow/withdraw on behalf of the sender.
Expand Down
11 changes: 0 additions & 11 deletions src/MorphoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ abstract contract MorphoStorage is Initializable, Ownable2StepUpgradeable {

IPool internal immutable _POOL; // The address of the pool.
IPoolAddressesProvider internal immutable _ADDRESSES_PROVIDER; // The address of the pool addresses provider.
bytes32 internal immutable _DOMAIN_SEPARATOR; // The domain separator as part of the EIP712.
uint8 internal immutable _E_MODE_CATEGORY_ID; // The e-mode category of the deployed Morpho.

/// STORAGE ///
Expand Down Expand Up @@ -51,16 +50,6 @@ abstract contract MorphoStorage is Initializable, Ownable2StepUpgradeable {
_ADDRESSES_PROVIDER = IPoolAddressesProvider(addressesProvider);
_POOL = IPool(_ADDRESSES_PROVIDER.getPool());

_DOMAIN_SEPARATOR = keccak256(
abi.encode(
Constants.EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(Constants.EIP712_NAME)),
keccak256(bytes(Constants.EIP712_VERSION)),
block.chainid,
address(this)
)
);

_E_MODE_CATEGORY_ID = eModeCategoryId;
}
}

0 comments on commit ab8b977

Please sign in to comment.