This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity =0.8.9; | |
// AppStorage.sol | |
struct AppStorage { | |
uint256 secondVar; | |
uint256 firstVar; | |
uint256 lastVar; | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DiamondStorage storage ds = diamondStorage(); | |
bytes4 functionSelector = bytes4(keccak256("myFunction(uint256)")); | |
// get facet address of function | |
address facet = ds.selectorToFacet[functionSelector]; | |
bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, 4); | |
(bool success, uint result) = address(facet).delegatecall(myFunctionCall); | |
require(success, "myFunction failed"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
DiamondStorage storage ds = diamondStorage(); | |
bytes4 functionSelector = bytes4(keccak256("myFunction(uint256)")); | |
// get facet address of function | |
address facet = ds.selectorToFacet[functionSelector]; | |
bytes memory myFunctionCall = abi.encodeWithSelector(functionSelector, 4); | |
(bool success, bytes memory result) = address(facet).delegatecall(myFunctionCall); | |
require(success, "myFunction failed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "./AppStorage.sol" | |
contract StakingFacet { | |
AppStorage internal s; | |
function myFacetFunction(uint256 _nextVar) external { | |
s.total = s.firstVar + _nextVar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// A contract that implements Diamond Storage. | |
library LibA { | |
// This struct contains state variables we care about. | |
struct DiamondStorage { | |
address owner; | |
bytes32 dataA; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// Find facet for function that is called and execute the | |
// function if a facet is found and return any value. | |
fallback() external payable { | |
// get facet from function selector | |
address facet = selectorTofacet[msg.sig]; | |
require(facet != address(0)); | |
// Execute external function from facet using delegatecall and return any value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LibAppStorage.sol | |
struct AppStorage { | |
uint256 secondVar; | |
uint256 firstVar; | |
uint256 lastVar; | |
... | |
} | |
library LibAppStorage { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LibAppStorage.sol | |
struct AppStorage { | |
uint256 secondVar; | |
uint256 firstVar; | |
uint256 lastVar; | |
... | |
} | |
library LibAppStorage { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LibAppStorage.sol | |
struct AppStorage { | |
uint256 secondVar; | |
uint256 firstVar; | |
uint256 lastVar; | |
... | |
} | |
library LibAppStorage { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AppStorage.sol | |
struct AppStorage { | |
uint256 secondVar; | |
uint256 firstVar; | |
uint256 lastVar; | |
... | |
} | |
// StakingFacet.sol | |
import "./AppStorage.sol" |