{ "_format": "hh-sol-artifact-1", "contractName": "DiamondLoupeFacet", "sourceName": "contracts/facets/DiamondLoupeFacet.sol", "abi": [{ "inputs": [{ "internalType": "bytes4", "name": "_functionSelector", "type": "bytes4" }], "name": "facetAddress", "outputs": [{ "internalType": "address", "name": "facetAddress_", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "facetAddresses", "outputs": [{ "internalType": "address[]", "name": "facetAddresses_", "type": "address[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_facet", "type": "address" }], "name": "facetFunctionSelectors", "outputs": [{ "internalType": "bytes4[]", "name": "_facetFunctionSelectors", "type": "bytes4[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "facets", "outputs": [{ "components": [{ "internalType": "address", "name": "facetAddress", "type": "address" }, { "internalType": "bytes4[]", "name": "functionSelectors", "type": "bytes4[]" }], "internalType": "struct IDiamondLoupe.Facet[]", "name": "facets_", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes4", "name": "_interfaceId", "type": "bytes4" }], "name": "supportsInterface", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }], "bytecode": "0x608060405234801561001057600080fd5b50611192806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806301ffc9a71461005c57806352ef6b2c1461008c5780637a0ed627146100aa578063adfca15e146100c8578063cdffacc6146100f8575b600080fd5b61007660048036038101906100719190610bdd565b610128565b6040516100839190610c25565b60405180910390f35b61009461019e565b6040516100a19190610d30565b60405180910390f35b6100b26103cc565b6040516100bf9190610f0f565b60405180910390f35b6100e260048036038101906100dd9190610f5d565b6108aa565b6040516100ef9190610ff9565b60405180910390f35b610112600480360381019061010d9190610bdd565b610a97565b60405161011f919061102a565b60405180910390f35b600080610133610b23565b9050806002016000847bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff16915050919050565b606060006101aa610b23565b90506000816001018054905090508067ffffffffffffffff8111156101d2576101d1611045565b5b6040519080825280602002602001820160405280156102005781602001602082028036833780820191505090505b5092506000805b828110156103c257600084600101828154811061022757610226611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000856000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000805b8581101561033c578881815181106102e6576102e5611074565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610329576001915061033c565b8080610334906110dc565b9150506102cb565b50801561034f57600090505050506103af565b8188868151811061036357610362611074565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505084806103a8906110dc565b9550505050505b80806103ba906110dc565b915050610207565b5080845250505090565b606060006103d8610b23565b90506000816001018054905090508067ffffffffffffffff811115610400576103ff611045565b5b60405190808252806020026020018201604052801561043957816020015b610426610b50565b81526020019060019003908161041e5790505b50925060008167ffffffffffffffff81111561045857610457611045565b5b6040519080825280602002602001820160405280156104865781602001602082028036833780820191505090505b5090506000805b838110156108355760008560010182815481106104ad576104ac611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000866000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000805b85811015610696578273ffffffffffffffffffffffffffffffffffffffff168a828151811061058357610582611074565b5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff160361068357838a82815181106105be576105bd611074565b5b6020026020010151602001518883815181106105dd576105dc611074565b5b602002602001015161ffff16815181106105fa576105f9611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168152505086818151811061065957610658611074565b5b60200260200101805180919061066e90611132565b61ffff1661ffff168152505060019150610696565b808061068e906110dc565b915050610551565b5080156106a95760009050505050610822565b818986815181106106bd576106bc611074565b5b60200260200101516000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508667ffffffffffffffff81111561071557610714611045565b5b6040519080825280602002602001820160405280156107435781602001602082028036833780820191505090505b5089868151811061075757610756611074565b5b6020026020010151602001819052508289868151811061077a57610779611074565b5b60200260200101516020015160008151811061079957610798611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168152505060018686815181106107fa576107f9611074565b5b602002602001019061ffff16908161ffff1681525050848061081b906110dc565b9550505050505b808061082d906110dc565b91505061048d565b5060005b8181101561089f57600083828151811061085657610855611074565b5b602002602001015161ffff169050600087838151811061087957610878611074565b5b602002602001015160200151905081815250508080610897906110dc565b915050610839565b508085525050505090565b606060006108b6610b23565b905060008160010180549050905060008167ffffffffffffffff8111156108e0576108df611045565b5b60405190808252806020026020018201604052801561090e5781602001602082028036833780820191505090505b50935060005b82811015610a8b57600084600101828154811061093457610933611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000856000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1603610a765781878581518110610a1b57610a1a611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815250508380610a72906110dc565b9450505b50508080610a83906110dc565b915050610914565b50808452505050919050565b600080610aa2610b23565b9050806000016000847bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16915050919050565b6000807fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c90508091505090565b6040518060400160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001606081525090565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610bba81610b85565b8114610bc557600080fd5b50565b600081359050610bd781610bb1565b92915050565b600060208284031215610bf357610bf2610b80565b5b6000610c0184828501610bc8565b91505092915050565b60008115159050919050565b610c1f81610c0a565b82525050565b6000602082019050610c3a6000830184610c16565b92915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c9782610c6c565b9050919050565b610ca781610c8c565b82525050565b6000610cb98383610c9e565b60208301905092915050565b6000602082019050919050565b6000610cdd82610c40565b610ce78185610c4b565b9350610cf283610c5c565b8060005b83811015610d23578151610d0a8882610cad565b9750610d1583610cc5565b925050600181019050610cf6565b5085935050505092915050565b60006020820190508181036000830152610d4a8184610cd2565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b610db381610b85565b82525050565b6000610dc58383610daa565b60208301905092915050565b6000602082019050919050565b6000610de982610d7e565b610df38185610d89565b9350610dfe83610d9a565b8060005b83811015610e2f578151610e168882610db9565b9750610e2183610dd1565b925050600181019050610e02565b5085935050505092915050565b6000604083016000830151610e546000860182610c9e565b5060208301518482036020860152610e6c8282610dde565b9150508091505092915050565b6000610e858383610e3c565b905092915050565b6000602082019050919050565b6000610ea582610d52565b610eaf8185610d5d565b935083602082028501610ec185610d6e565b8060005b85811015610efd5784840389528151610ede8582610e79565b9450610ee983610e8d565b925060208a01995050600181019050610ec5565b50829750879550505050505092915050565b60006020820190508181036000830152610f298184610e9a565b905092915050565b610f3a81610c8c565b8114610f4557600080fd5b50565b600081359050610f5781610f31565b92915050565b600060208284031215610f7357610f72610b80565b5b6000610f8184828501610f48565b91505092915050565b600082825260208201905092915050565b6000610fa682610d7e565b610fb08185610f8a565b9350610fbb83610d9a565b8060005b83811015610fec578151610fd38882610db9565b9750610fde83610dd1565b925050600181019050610fbf565b5085935050505092915050565b600060208201905081810360008301526110138184610f9b565b905092915050565b61102481610c8c565b82525050565b600060208201905061103f600083018461101b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000819050919050565b60006110e7826110d2565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611119576111186110a3565b5b600182019050919050565b600061ffff82169050919050565b600061113d82611124565b915061ffff8203611151576111506110a3565b5b60018201905091905056fea26469706673582212209465a54b9a711a60d66072a40924ed0089961902bba244df4c48befc59004a2364736f6c63430008110033", "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c806301ffc9a71461005c57806352ef6b2c1461008c5780637a0ed627146100aa578063adfca15e146100c8578063cdffacc6146100f8575b600080fd5b61007660048036038101906100719190610bdd565b610128565b6040516100839190610c25565b60405180910390f35b61009461019e565b6040516100a19190610d30565b60405180910390f35b6100b26103cc565b6040516100bf9190610f0f565b60405180910390f35b6100e260048036038101906100dd9190610f5d565b6108aa565b6040516100ef9190610ff9565b60405180910390f35b610112600480360381019061010d9190610bdd565b610a97565b60405161011f919061102a565b60405180910390f35b600080610133610b23565b9050806002016000847bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff16915050919050565b606060006101aa610b23565b90506000816001018054905090508067ffffffffffffffff8111156101d2576101d1611045565b5b6040519080825280602002602001820160405280156102005781602001602082028036833780820191505090505b5092506000805b828110156103c257600084600101828154811061022757610226611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000856000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000805b8581101561033c578881815181106102e6576102e5611074565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610329576001915061033c565b8080610334906110dc565b9150506102cb565b50801561034f57600090505050506103af565b8188868151811061036357610362611074565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505084806103a8906110dc565b9550505050505b80806103ba906110dc565b915050610207565b5080845250505090565b606060006103d8610b23565b90506000816001018054905090508067ffffffffffffffff811115610400576103ff611045565b5b60405190808252806020026020018201604052801561043957816020015b610426610b50565b81526020019060019003908161041e5790505b50925060008167ffffffffffffffff81111561045857610457611045565b5b6040519080825280602002602001820160405280156104865781602001602082028036833780820191505090505b5090506000805b838110156108355760008560010182815481106104ad576104ac611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000866000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000805b85811015610696578273ffffffffffffffffffffffffffffffffffffffff168a828151811061058357610582611074565b5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff160361068357838a82815181106105be576105bd611074565b5b6020026020010151602001518883815181106105dd576105dc611074565b5b602002602001015161ffff16815181106105fa576105f9611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168152505086818151811061065957610658611074565b5b60200260200101805180919061066e90611132565b61ffff1661ffff168152505060019150610696565b808061068e906110dc565b915050610551565b5080156106a95760009050505050610822565b818986815181106106bd576106bc611074565b5b60200260200101516000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508667ffffffffffffffff81111561071557610714611045565b5b6040519080825280602002602001820160405280156107435781602001602082028036833780820191505090505b5089868151811061075757610756611074565b5b6020026020010151602001819052508289868151811061077a57610779611074565b5b60200260200101516020015160008151811061079957610798611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168152505060018686815181106107fa576107f9611074565b5b602002602001019061ffff16908161ffff1681525050848061081b906110dc565b9550505050505b808061082d906110dc565b91505061048d565b5060005b8181101561089f57600083828151811061085657610855611074565b5b602002602001015161ffff169050600087838151811061087957610878611074565b5b602002602001015160200151905081815250508080610897906110dc565b915050610839565b508085525050505090565b606060006108b6610b23565b905060008160010180549050905060008167ffffffffffffffff8111156108e0576108df611045565b5b60405190808252806020026020018201604052801561090e5781602001602082028036833780820191505090505b50935060005b82811015610a8b57600084600101828154811061093457610933611074565b5b90600052602060002090600891828204019190066004029054906101000a900460e01b90506000856000016000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1603610a765781878581518110610a1b57610a1a611074565b5b60200260200101907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815250508380610a72906110dc565b9450505b50508080610a83906110dc565b915050610914565b50808452505050919050565b600080610aa2610b23565b9050806000016000847bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16915050919050565b6000807fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c90508091505090565b6040518060400160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001606081525090565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610bba81610b85565b8114610bc557600080fd5b50565b600081359050610bd781610bb1565b92915050565b600060208284031215610bf357610bf2610b80565b5b6000610c0184828501610bc8565b91505092915050565b60008115159050919050565b610c1f81610c0a565b82525050565b6000602082019050610c3a6000830184610c16565b92915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c9782610c6c565b9050919050565b610ca781610c8c565b82525050565b6000610cb98383610c9e565b60208301905092915050565b6000602082019050919050565b6000610cdd82610c40565b610ce78185610c4b565b9350610cf283610c5c565b8060005b83811015610d23578151610d0a8882610cad565b9750610d1583610cc5565b925050600181019050610cf6565b5085935050505092915050565b60006020820190508181036000830152610d4a8184610cd2565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b610db381610b85565b82525050565b6000610dc58383610daa565b60208301905092915050565b6000602082019050919050565b6000610de982610d7e565b610df38185610d89565b9350610dfe83610d9a565b8060005b83811015610e2f578151610e168882610db9565b9750610e2183610dd1565b925050600181019050610e02565b5085935050505092915050565b6000604083016000830151610e546000860182610c9e565b5060208301518482036020860152610e6c8282610dde565b9150508091505092915050565b6000610e858383610e3c565b905092915050565b6000602082019050919050565b6000610ea582610d52565b610eaf8185610d5d565b935083602082028501610ec185610d6e565b8060005b85811015610efd5784840389528151610ede8582610e79565b9450610ee983610e8d565b925060208a01995050600181019050610ec5565b50829750879550505050505092915050565b60006020820190508181036000830152610f298184610e9a565b905092915050565b610f3a81610c8c565b8114610f4557600080fd5b50565b600081359050610f5781610f31565b92915050565b600060208284031215610f7357610f72610b80565b5b6000610f8184828501610f48565b91505092915050565b600082825260208201905092915050565b6000610fa682610d7e565b610fb08185610f8a565b9350610fbb83610d9a565b8060005b83811015610fec578151610fd38882610db9565b9750610fde83610dd1565b925050600181019050610fbf565b5085935050505092915050565b600060208201905081810360008301526110138184610f9b565b905092915050565b61102481610c8c565b82525050565b600060208201905061103f600083018461101b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000819050919050565b60006110e7826110d2565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611119576111186110a3565b5b600182019050919050565b600061ffff82169050919050565b600061113d82611124565b915061ffff8203611151576111506110a3565b5b60018201905091905056fea26469706673582212209465a54b9a711a60d66072a40924ed0089961902bba244df4c48befc59004a2364736f6c63430008110033", "linkReferences": {}, "deployedLinkReferences": {}, "source": { "solcVersion": "0.8.17+commit.8df45f5f", "input": "{\"language\":\"Solidity\",\"sources\":{\"contracts/facets/DiamondLoupeFacet.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n/******************************************************************************\\\\\\n* Author: Nick Mudge <nick@perfectabstractions.com>, Twitter/Github: @mudgen\\n* EIP-2535 Diamonds\\n/******************************************************************************/\\n\\n// The functions in DiamondLoupeFacet MUST be added to a diamond.\\n// The EIP-2535 Diamond standard requires these functions.\\n\\nimport { LibDiamond } from  \\\"../libraries/LibDiamond.sol\\\";\\nimport { IDiamondLoupe } from \\\"../interfaces/IDiamondLoupe.sol\\\";\\nimport { IERC165 } from \\\"../interfaces/IERC165.sol\\\";\\n\\ncontract DiamondLoupeFacet is IDiamondLoupe, IERC165 {\\n    // Diamond Loupe Functions\\n    ////////////////////////////////////////////////////////////////////\\n    /// These functions are expected to be called frequently by tools.\\n    //\\n    // struct Facet {\\n    //     address facetAddress;\\n    //     bytes4[] functionSelectors;\\n    // }\\n    /// @notice Gets all facets and their selectors.\\n    /// @return facets_ Facet\\n    function facets() external override view returns (Facet[] memory facets_) {\\n        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();\\n        uint256 selectorCount = ds.selectors.length;\\n        // create an array set to the maximum size possible\\n        facets_ = new Facet[](selectorCount);\\n        // create an array for counting the number of selectors for each facet\\n        uint16[] memory numFacetSelectors = new uint16[](selectorCount);\\n        // total number of facets\\n        uint256 numFacets;\\n        // loop through function selectors\\n        for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) {\\n            bytes4 selector = ds.selectors[selectorIndex];\\n            address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress;\\n            bool continueLoop = false;\\n            // find the functionSelectors array for selector and add selector to it\\n            for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {\\n                if (facets_[facetIndex].facetAddress == facetAddress_) {\\n                    facets_[facetIndex].functionSelectors[numFacetSelectors[facetIndex]] = selector;                                   \\n                    numFacetSelectors[facetIndex]++;\\n                    continueLoop = true;\\n                    break;\\n                }\\n            }\\n            // if functionSelectors array exists for selector then continue loop\\n            if (continueLoop) {\\n                continueLoop = false;\\n                continue;\\n            }\\n            // create a new functionSelectors array for selector\\n            facets_[numFacets].facetAddress = facetAddress_;\\n            facets_[numFacets].functionSelectors = new bytes4[](selectorCount);\\n            facets_[numFacets].functionSelectors[0] = selector;\\n            numFacetSelectors[numFacets] = 1;\\n            numFacets++;\\n        }\\n        for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {\\n            uint256 numSelectors = numFacetSelectors[facetIndex];\\n            bytes4[] memory selectors = facets_[facetIndex].functionSelectors;\\n            // setting the number of selectors\\n            assembly {\\n                mstore(selectors, numSelectors)\\n            }\\n        }\\n        // setting the number of facets\\n        assembly {\\n            mstore(facets_, numFacets)\\n        }\\n    }\\n\\n    /// @notice Gets all the function selectors supported by a specific facet.\\n    /// @param _facet The facet address.\\n    /// @return _facetFunctionSelectors The selectors associated with a facet address.\\n    function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory _facetFunctionSelectors) {\\n        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();\\n        uint256 selectorCount = ds.selectors.length;\\n        uint256 numSelectors;\\n        _facetFunctionSelectors = new bytes4[](selectorCount);\\n        // loop through function selectors\\n        for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) {\\n            bytes4 selector = ds.selectors[selectorIndex];\\n            address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress;\\n            if (_facet == facetAddress_) {\\n                _facetFunctionSelectors[numSelectors] = selector;\\n                numSelectors++;\\n            }\\n        }\\n        // Set the number of selectors in the array\\n        assembly {\\n            mstore(_facetFunctionSelectors, numSelectors)\\n        }\\n    }\\n\\n    /// @notice Get all the facet addresses used by a diamond.\\n    /// @return facetAddresses_\\n    function facetAddresses() external override view returns (address[] memory facetAddresses_) {\\n        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();\\n        uint256 selectorCount = ds.selectors.length;\\n        // create an array set to the maximum size possible\\n        facetAddresses_ = new address[](selectorCount);\\n        uint256 numFacets;\\n        // loop through function selectors\\n        for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) {\\n            bytes4 selector = ds.selectors[selectorIndex];\\n            address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress;\\n            bool continueLoop = false;\\n            // see if we have collected the address already and break out of loop if we have\\n            for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {\\n                if (facetAddress_ == facetAddresses_[facetIndex]) {\\n                    continueLoop = true;\\n                    break;\\n                }\\n            }\\n            // continue loop if we already have the address\\n            if (continueLoop) {\\n                continueLoop = false;\\n                continue;\\n            }\\n            // include address\\n            facetAddresses_[numFacets] = facetAddress_;\\n            numFacets++;\\n        }\\n        // Set the number of facet addresses in the array\\n        assembly {\\n            mstore(facetAddresses_, numFacets)\\n        }\\n    }\\n\\n    /// @notice Gets the facet address that supports the given selector.\\n    /// @dev If facet is not found return address(0).\\n    /// @param _functionSelector The function selector.\\n    /// @return facetAddress_ The facet address.\\n    function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) {\\n        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();\\n        facetAddress_ = ds.facetAddressAndSelectorPosition[_functionSelector].facetAddress;\\n    }\\n\\n    // This implements ERC-165.\\n    function supportsInterface(bytes4 _interfaceId) external override view returns (bool) {\\n        LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();\\n        return ds.supportedInterfaces[_interfaceId];\\n    }\\n}\\n\"},\"contracts/libraries/LibDiamond.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n\\n/******************************************************************************\\\\\\n* Author: Nick Mudge <nick@perfectabstractions.com>, Twitter/Github: @mudgen\\n* EIP-2535 Diamonds\\n/******************************************************************************/\\nimport { IDiamond } from \\\"../interfaces/IDiamond.sol\\\";\\nimport { IDiamondCut } from \\\"../interfaces/IDiamondCut.sol\\\";\\n\\n// Remember to add the loupe functions from DiamondLoupeFacet to the diamond.\\n// The loupe functions are required by the EIP2535 Diamonds standard\\n\\nerror NoSelectorsGivenToAdd();\\nerror NotContractOwner(address _user, address _contractOwner);\\nerror NoSelectorsProvidedForFacetForCut(address _facetAddress);\\nerror CannotAddSelectorsToZeroAddress(bytes4[] _selectors);\\nerror NoBytecodeAtAddress(address _contractAddress, string _message);\\nerror IncorrectFacetCutAction(uint8 _action);\\nerror CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector);\\nerror CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors);\\nerror CannotReplaceImmutableFunction(bytes4 _selector);\\nerror CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector);\\nerror CannotReplaceFunctionThatDoesNotExists(bytes4 _selector);\\nerror RemoveFacetAddressMustBeZeroAddress(address _facetAddress);\\nerror CannotRemoveFunctionThatDoesNotExist(bytes4 _selector);\\nerror CannotRemoveImmutableFunction(bytes4 _selector);\\nerror InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata);\\n\\nlibrary LibDiamond {\\n    bytes32 constant DIAMOND_STORAGE_POSITION = keccak256(\\\"diamond.standard.diamond.storage\\\");\\n\\n    struct FacetAddressAndSelectorPosition {\\n        address facetAddress;\\n        uint16 selectorPosition;\\n    }\\n\\n    struct DiamondStorage {\\n        // function selector => facet address and selector position in selectors array\\n        mapping(bytes4 => FacetAddressAndSelectorPosition) facetAddressAndSelectorPosition;\\n        bytes4[] selectors;\\n        mapping(bytes4 => bool) supportedInterfaces;\\n        // owner of the contract\\n        address contractOwner;\\n    }\\n\\n    function diamondStorage() internal pure returns (DiamondStorage storage ds) {\\n        bytes32 position = DIAMOND_STORAGE_POSITION;\\n        assembly {\\n            ds.slot := position\\n        }\\n    }\\n\\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\\n\\n    function setContractOwner(address _newOwner) internal {\\n        DiamondStorage storage ds = diamondStorage();\\n        address previousOwner = ds.contractOwner;\\n        ds.contractOwner = _newOwner;\\n        emit OwnershipTransferred(previousOwner, _newOwner);\\n    }\\n\\n    function contractOwner() internal view returns (address contractOwner_) {\\n        contractOwner_ = diamondStorage().contractOwner;\\n    }\\n\\n    function enforceIsContractOwner() internal view {\\n        if(msg.sender != diamondStorage().contractOwner) {\\n            revert NotContractOwner(msg.sender, diamondStorage().contractOwner);\\n        }        \\n    }\\n\\n    event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);\\n\\n    // Internal function version of diamondCut\\n    function diamondCut(\\n        IDiamondCut.FacetCut[] memory _diamondCut,\\n        address _init,\\n        bytes memory _calldata\\n    ) internal {\\n        for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) {\\n            bytes4[] memory functionSelectors = _diamondCut[facetIndex].functionSelectors;\\n            address facetAddress = _diamondCut[facetIndex].facetAddress;\\n            if(functionSelectors.length == 0) {\\n                revert NoSelectorsProvidedForFacetForCut(facetAddress);\\n            }\\n            IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action;\\n            if (action == IDiamond.FacetCutAction.Add) {\\n                addFunctions(facetAddress, functionSelectors);\\n            } else if (action == IDiamond.FacetCutAction.Replace) {\\n                replaceFunctions(facetAddress, functionSelectors);\\n            } else if (action == IDiamond.FacetCutAction.Remove) {\\n                removeFunctions(facetAddress, functionSelectors);\\n            } else {\\n                revert IncorrectFacetCutAction(uint8(action));\\n            }\\n        }\\n        emit DiamondCut(_diamondCut, _init, _calldata);\\n        initializeDiamondCut(_init, _calldata);\\n    }\\n\\n    function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {        \\n        if(_facetAddress == address(0)) {\\n            revert CannotAddSelectorsToZeroAddress(_functionSelectors);\\n        }\\n        DiamondStorage storage ds = diamondStorage();\\n        uint16 selectorCount = uint16(ds.selectors.length);                \\n        enforceHasContractCode(_facetAddress, \\\"LibDiamondCut: Add facet has no code\\\");\\n        for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\\n            bytes4 selector = _functionSelectors[selectorIndex];\\n            address oldFacetAddress = ds.facetAddressAndSelectorPosition[selector].facetAddress;\\n            if(oldFacetAddress != address(0)) {\\n                revert CannotAddFunctionToDiamondThatAlreadyExists(selector);\\n            }            \\n            ds.facetAddressAndSelectorPosition[selector] = FacetAddressAndSelectorPosition(_facetAddress, selectorCount);\\n            ds.selectors.push(selector);\\n            selectorCount++;\\n        }\\n    }\\n\\n    function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {        \\n        DiamondStorage storage ds = diamondStorage();\\n        if(_facetAddress == address(0)) {\\n            revert CannotReplaceFunctionsFromFacetWithZeroAddress(_functionSelectors);\\n        }\\n        enforceHasContractCode(_facetAddress, \\\"LibDiamondCut: Replace facet has no code\\\");\\n        for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\\n            bytes4 selector = _functionSelectors[selectorIndex];\\n            address oldFacetAddress = ds.facetAddressAndSelectorPosition[selector].facetAddress;\\n            // can't replace immutable functions -- functions defined directly in the diamond in this case\\n            if(oldFacetAddress == address(this)) {\\n                revert CannotReplaceImmutableFunction(selector);\\n            }\\n            if(oldFacetAddress == _facetAddress) {\\n                revert CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(selector);\\n            }\\n            if(oldFacetAddress == address(0)) {\\n                revert CannotReplaceFunctionThatDoesNotExists(selector);\\n            }\\n            // replace old facet address\\n            ds.facetAddressAndSelectorPosition[selector].facetAddress = _facetAddress;\\n        }\\n    }\\n\\n    function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {        \\n        DiamondStorage storage ds = diamondStorage();\\n        uint256 selectorCount = ds.selectors.length;\\n        if(_facetAddress != address(0)) {\\n            revert RemoveFacetAddressMustBeZeroAddress(_facetAddress);\\n        }        \\n        for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\\n            bytes4 selector = _functionSelectors[selectorIndex];\\n            FacetAddressAndSelectorPosition memory oldFacetAddressAndSelectorPosition = ds.facetAddressAndSelectorPosition[selector];\\n            if(oldFacetAddressAndSelectorPosition.facetAddress == address(0)) {\\n                revert CannotRemoveFunctionThatDoesNotExist(selector);\\n            }\\n            \\n            \\n            // can't remove immutable functions -- functions defined directly in the diamond\\n            if(oldFacetAddressAndSelectorPosition.facetAddress == address(this)) {\\n                revert CannotRemoveImmutableFunction(selector);\\n            }\\n            // replace selector with last selector\\n            selectorCount--;\\n            if (oldFacetAddressAndSelectorPosition.selectorPosition != selectorCount) {\\n                bytes4 lastSelector = ds.selectors[selectorCount];\\n                ds.selectors[oldFacetAddressAndSelectorPosition.selectorPosition] = lastSelector;\\n                ds.facetAddressAndSelectorPosition[lastSelector].selectorPosition = oldFacetAddressAndSelectorPosition.selectorPosition;\\n            }\\n            // delete last selector\\n            ds.selectors.pop();\\n            delete ds.facetAddressAndSelectorPosition[selector];\\n        }\\n    }\\n\\n    function initializeDiamondCut(address _init, bytes memory _calldata) internal {\\n        if (_init == address(0)) {\\n            return;\\n        }\\n        enforceHasContractCode(_init, \\\"LibDiamondCut: _init address has no code\\\");        \\n        (bool success, bytes memory error) = _init.delegatecall(_calldata);\\n        if (!success) {\\n            if (error.length > 0) {\\n                // bubble up error\\n                /// @solidity memory-safe-assembly\\n                assembly {\\n                    let returndata_size := mload(error)\\n                    revert(add(32, error), returndata_size)\\n                }\\n            } else {\\n                revert InitializationFunctionReverted(_init, _calldata);\\n            }\\n        }        \\n    }\\n\\n    function enforceHasContractCode(address _contract, string memory _errorMessage) internal view {\\n        uint256 contractSize;\\n        assembly {\\n            contractSize := extcodesize(_contract)\\n        }\\n        if(contractSize == 0) {\\n            revert NoBytecodeAtAddress(_contract, _errorMessage);\\n        }        \\n    }\\n}\\n\"},\"contracts/interfaces/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n\\ninterface IERC165 {\\n    /// @notice Query if a contract implements an interface\\n    /// @param interfaceId The interface identifier, as specified in ERC-165\\n    /// @dev Interface identification is specified in ERC-165. This function\\n    ///  uses less than 30,000 gas.\\n    /// @return `true` if the contract implements `interfaceID` and\\n    ///  `interfaceID` is not 0xffffffff, `false` otherwise\\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\"},\"contracts/interfaces/IDiamondLoupe.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n\\n/******************************************************************************\\\\\\n* Author: Nick Mudge <nick@perfectabstractions.com>, Twitter/Github: @mudgen\\n* EIP-2535 Diamonds\\n/******************************************************************************/\\n\\n// A loupe is a small magnifying glass used to look at diamonds.\\n// These functions look at diamonds\\ninterface IDiamondLoupe {\\n    /// These functions are expected to be called frequently\\n    /// by tools.\\n\\n    struct Facet {\\n        address facetAddress;\\n        bytes4[] functionSelectors;\\n    }\\n\\n    /// @notice Gets all facet addresses and their four byte function selectors.\\n    /// @return facets_ Facet\\n    function facets() external view returns (Facet[] memory facets_);\\n\\n    /// @notice Gets all the function selectors supported by a specific facet.\\n    /// @param _facet The facet address.\\n    /// @return facetFunctionSelectors_\\n    function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_);\\n\\n    /// @notice Get all the facet addresses used by a diamond.\\n    /// @return facetAddresses_\\n    function facetAddresses() external view returns (address[] memory facetAddresses_);\\n\\n    /// @notice Gets the facet that supports the given selector.\\n    /// @dev If facet is not found return address(0).\\n    /// @param _functionSelector The function selector.\\n    /// @return facetAddress_ The facet address.\\n    function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_);\\n}\\n\"},\"contracts/interfaces/IDiamond.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n\\n/******************************************************************************\\\\\\n* Author: Nick Mudge <nick@perfectabstractions.com>, Twitter/Github: @mudgen\\n* EIP-2535 Diamonds\\n/******************************************************************************/\\n\\ninterface IDiamond {\\n    enum FacetCutAction {Add, Replace, Remove}\\n    // Add=0, Replace=1, Remove=2\\n\\n    struct FacetCut {\\n        address facetAddress;\\n        FacetCutAction action;\\n        bytes4[] functionSelectors;\\n    }\\n\\n    event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);\\n}\"},\"contracts/interfaces/IDiamondCut.sol\":{\"content\":\"// SPDX-License-Identifier: CC0-1.0\\npragma solidity ^0.8.0;\\n\\n/******************************************************************************\\\\\\n* Author: Nick Mudge <nick@perfectabstractions.com>, Twitter/Github: @mudgen\\n* EIP-2535 Diamonds\\n/******************************************************************************/\\n\\nimport { IDiamond } from \\\"./IDiamond.sol\\\";\\n\\ninterface IDiamondCut is IDiamond {    \\n\\n    /// @notice Add/replace/remove any number of functions and optionally execute\\n    ///         a function with delegatecall\\n    /// @param _diamondCut Contains the facet addresses and function selectors\\n    /// @param _init The address of the contract or facet to execute _calldata\\n    /// @param _calldata A function call, including function selector and arguments\\n    ///                  _calldata is executed with delegatecall on _init\\n    function diamondCut(\\n        FacetCut[] calldata _diamondCut,\\n        address _init,\\n        bytes calldata _calldata\\n    ) external;    \\n}\\n\"}},\"settings\":{\"optimizer\":{\"enabled\":false,\"runs\":200},\"outputSelection\":{\"*\":{\"*\":[\"abi\",\"evm.bytecode\",\"evm.deployedBytecode\",\"evm.methodIdentifiers\",\"metadata\"],\"\":[\"ast\"]}}}}" } }
