Skip to content

Commit d99a359

Browse files
authored
Merge pull request #15 from dadadave80/chore/update-diamond
Refactor Diamond proxy delegatecall logic
2 parents e4d125f + 7755954 commit d99a359

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/Diamond.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ abstract contract Diamond {
5151
/// @dev Reads the facet address from diamond storage and performs a delegatecall; reverts if selector is not found
5252
fallback() external payable virtual {
5353
_beforeDelegate();
54-
_delegate(_implementation());
54+
_delegate(_facet());
5555
}
5656

5757
/// @notice Retrieves the implementation address for the current function call
58-
/// @dev Implementation and Facet are synonyms in a Diamond Proxy
59-
function _implementation() internal virtual returns (address) {
58+
/// @dev A Facet is one of many implementations in a Diamond Proxy
59+
function _facet() internal virtual returns (address) {
6060
return LibDiamond._selectorToFacet(msg.sig);
6161
}
6262

6363
/// @notice Internal function to perform a delegatecall to an implementation
64-
/// @param _facet Address of the implementation to delegate to
65-
function _delegate(address _facet) internal virtual {
64+
/// @param _implementation Address of the implementation to delegate to
65+
function _delegate(address _implementation) internal virtual {
6666
assembly {
6767
// Copy calldata to memory
6868
calldatacopy(0, 0, calldatasize())
6969

7070
// Delegate call to implementation
71-
let result := delegatecall(gas(), _facet, 0, calldatasize(), 0, 0)
71+
let result := delegatecall(gas(), _implementation, 0, calldatasize(), 0, 0)
7272

7373
// Copy returned data
7474
returndatacopy(0, 0, returndatasize())
@@ -87,5 +87,5 @@ abstract contract Diamond {
8787

8888
/// @notice Internal hook function to run before a delegatecall to the facet
8989
/// @dev This function can be replaced to perform additional logic before the delegatecall
90-
function _beforeDelegate() internal virtual;
90+
function _beforeDelegate() internal virtual {}
9191
}

0 commit comments

Comments
 (0)