- Contract name:
- DiamondInit
- Optimization enabled
- false
- Compiler version
- v0.8.17+commit.8df45f5f
- Verified at
- 2024-05-22T17:59:22.856954Z
contracts/upgradeInitializers/DiamondInit.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/******************************************************************************\* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535** Implementation of a diamond./******************************************************************************/import { LibDiamond } from "../libraries/LibDiamond.sol";import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol";import { IDiamondCut } from "../interfaces/IDiamondCut.sol";import { IERC173 } from "../interfaces/IERC173.sol";import { IERC165 } from "../interfaces/IERC165.sol";// It is expected that this contract is customized if you want to deploy your diamond// with data from a deployment script. Use the init function to initialize state variables// of your diamond. Add parameters to the init funciton if you need to.// Adding parameters to the `init` or other functions you add here can make a single deployed// DiamondInit contract reusable accross upgrades, and can be used for multiple diamonds.contract DiamondInit {// You can add parameters to this function in order to pass in// data to set your own state variablesfunction init() external {// adding ERC165 dataLibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();ds.supportedInterfaces[type(IERC165).interfaceId] = true;ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;ds.supportedInterfaces[type(IERC173).interfaceId] = true;// add your own state variables// EIP-2535 specifies that the `diamondCut` function takes two optional// arguments: address _init and bytes calldata _calldata// These arguments are used to execute an arbitrary function using delegatecall// in order to set state variables in the diamond during deployment or an upgrade// More info here: https://eips.ethereum.org/EIPS/eip-2535#diamond-interface}
contracts/interfaces/IDiamond.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/******************************************************************************\* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535/******************************************************************************/interface IDiamond {enum FacetCutAction {Add,Replace,Remove}// Add=0, Replace=1, Remove=2struct FacetCut {address facetAddress;FacetCutAction action;bytes4[] functionSelectors;}event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);}
contracts/interfaces/IDiamondCut.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/******************************************************************************\* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535/******************************************************************************/import { IDiamond } from "./IDiamond.sol";interface IDiamondCut is IDiamond {/// @notice Add/replace/remove any number of functions and optionally execute/// a function with delegatecall/// @param _diamondCut Contains the facet addresses and function selectors/// @param _init The address of the contract or facet to execute _calldata/// @param _calldata A function call, including function selector and arguments/// _calldata is executed with delegatecall on _initfunction diamondCut(FacetCut[] calldata _diamondCut,address _init,bytes calldata _calldata) external;}
contracts/interfaces/IDiamondLoupe.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/******************************************************************************\* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535/******************************************************************************/// A loupe is a small magnifying glass used to look at diamonds.// These functions look at diamondsinterface IDiamondLoupe {/// These functions are expected to be called frequently/// by tools.struct Facet {address facetAddress;bytes4[] functionSelectors;}/// @notice Gets all facet addresses and their four byte function selectors./// @return facets_ Facetfunction facets() external view returns (Facet[] memory facets_);/// @notice Gets all the function selectors supported by a specific facet./// @param _facet The facet address./// @return facetFunctionSelectors_function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_);/// @notice Get all the facet addresses used by a diamond./// @return facetAddresses_function facetAddresses()externalviewreturns (address[] memory facetAddresses_);/// @notice Gets the facet that supports the given selector./// @dev If facet is not found return address(0)./// @param _functionSelector The function selector./// @return facetAddress_ The facet address.
contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;interface IERC165 {/// @notice Query if a contract implements an interface/// @param interfaceId The interface identifier, as specified in ERC-165/// @dev Interface identification is specified in ERC-165. This function/// uses less than 30,000 gas./// @return `true` if the contract implements `interfaceID` and/// `interfaceID` is not 0xffffffff, `false` otherwisefunction supportsInterface(bytes4 interfaceId) external view returns (bool);}
contracts/interfaces/IERC173.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/// @title ERC-173 Contract Ownership Standard/// Note: the ERC-165 identifier for this interface is 0x7f5828d0/* is ERC165 */interface IERC173 {/// @dev This emits when ownership of a contract changes.event OwnershipTransferred(address indexed previousOwner,address indexed newOwner);/// @notice Get the address of the owner/// @return owner_ The address of the owner.function owner() external view returns (address owner_);/// @notice Set the address of the new owner of the contract/// @dev Set _newOwner to address(0) to renounce any ownership./// @param _newOwner The address of the new owner of the contractfunction transferOwnership(address _newOwner) external;}
contracts/libraries/LibDiamond.sol
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;/******************************************************************************\* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535/******************************************************************************/import { IDiamond } from "../interfaces/IDiamond.sol";import { IDiamondCut } from "../interfaces/IDiamondCut.sol";// Remember to add the loupe functions from DiamondLoupeFacet to the diamond.// The loupe functions are required by the EIP2535 Diamonds standarderror NoSelectorsGivenToAdd();error NotContractOwner(address _user, address _contractOwner);error NoSelectorsProvidedForFacetForCut(address _facetAddress);error CannotAddSelectorsToZeroAddress(bytes4[] _selectors);error NoBytecodeAtAddress(address _contractAddress, string _message);error IncorrectFacetCutAction(uint8 _action);error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector);error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors);error CannotReplaceImmutableFunction(bytes4 _selector);error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector);error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector);error RemoveFacetAddressMustBeZeroAddress(address _facetAddress);error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector);error CannotRemoveImmutableFunction(bytes4 _selector);error InitializationFunctionReverted(address _initializationContractAddress,bytes _calldata);library LibDiamond {bytes32 constant DIAMOND_STORAGE_POSITION =keccak256("diamond.standard.diamond.storage");struct FacetAddressAndSelectorPosition {address facetAddress;uint16 selectorPosition;
Contract ABI
[{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"init","inputs":[]}]
Contract Creation Code
0x608060405234801561001057600080fd5b506102dc806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e1c7392a14610030575b600080fd5b61003861003a565b005b6000610044610279565b905060018160020160007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f1f931c1c000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f48e2b093000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f7f5828d0000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000807fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c9050809150509056fea264697066735822122012c33f2c8d6edd972b71548250f39269ca859509ddbc67aa408fcd737b66751b64736f6c63430008110033
Deployed ByteCode
0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e1c7392a14610030575b600080fd5b61003861003a565b005b6000610044610279565b905060018160020160007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f1f931c1c000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f48e2b093000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555060018160020160007f7f5828d0000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b6000807fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c9050809150509056fea264697066735822122012c33f2c8d6edd972b71548250f39269ca859509ddbc67aa408fcd737b66751b64736f6c63430008110033