Skip to content

Instantly share code, notes, and snippets.

@ssadler
Created April 7, 2023 19:26
Show Gist options
  • Save ssadler/cd55feba60cfb677f04eb8ca73012040 to your computer and use it in GitHub Desktop.
Save ssadler/cd55feba60cfb677f04eb8ca73012040 to your computer and use it in GitHub Desktop.
pragma solidity ^0.8.16;
import '../lib/diamond-3-hardhat/contracts/facets/DiamondCutFacet.sol';
import '../lib/diamond-3-hardhat/contracts/facets/OwnershipFacet.sol';
import '../lib/diamond-3-hardhat/contracts/facets/DiamondLoupeFacet.sol';
import '../lib/diamond-3-hardhat/contracts/libraries/LibDiamond.sol';
import '../lib/diamond-3-hardhat/contracts/interfaces/IERC165.sol';
import '../lib/diamond-3-hardhat/contracts/interfaces/IERC173.sol';
contract QueryDiamond is OwnershipFacet, DiamondCutFacet, DiamondLoupeFacet {
constructor() {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
ds.contractOwner = msg.sender;
ds.supportedInterfaces[type(IERC165).interfaceId] = true;
ds.supportedInterfaces[type(IERC173).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
}
function lookupSelector(bytes4 selector) external view returns (address) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.selectorToFacetAndPosition[selector].facetAddress;
}
function setImmutableFacet(address facet) external {
LibDiamond.enforceIsContractOwner();
LibDiamond.setImmutableFacet(facet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment