This file contains hidden or 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
| /** | |
| *Submitted for verification at polygonscan.com on 2021-06-13 | |
| */ | |
| pragma solidity 0.5.17; | |
| /* | |
| * @dev Provides information about the current execution context, including the | |
| * sender of the transaction and its data. While these are generally available |
This file contains hidden or 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.11; | |
| function doIt() external { | |
| uint256 length = myArray.length; // state read | |
| uint b; | |
| for(uint256 i; i < length; i++) { // local reads | |
| b++; // local write | |
| } | |
| mySum = b; // state write |
This file contains hidden or 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.11; | |
| // Note: A facet is a contract used by a diamond. | |
| // Note: This is a contrived example to show how to share internal functions between facets | |
| // Note: It is not an accurate or complete implementation | |
| // This design of sharing internal functions between facets works because remember the diamond proxy holds all the | |
| // data and the facets read and write to the diamond proxy contract storage-- not to their own contract storage. |
This file contains hidden or 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; | |
| library MyLib { | |
| function appStorage() | |
| internal | |
| pure | |
| returns (AppStorage storage ds) | |
| { | |
| assembly { |
This file contains hidden or 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; | |
| import "./AppStorage.sol" | |
| contract StakingFacet { | |
| AppStorage internal s; | |
| function myFacetFunction() external { | |
| s.lastVar = s.firstVar + s.secondVar; |
This file contains hidden or 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; | |
| import "./AppStorage.sol" | |
| contract StakingFacet { | |
| AppStorage internal s; | |
| ... |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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; |