编译器
0.8.26+commit.8a97fa7a
文件 1 的 43:AddressUtils.sol
pragma solidity ^0.8.20;
import { UintUtils } from './UintUtils.sol';
library AddressUtils {
using UintUtils for uint256;
error AddressUtils__InsufficientBalance();
error AddressUtils__NotContract();
error AddressUtils__SendValueFailed();
function toString(address account) internal pure returns (string memory) {
return uint256(uint160(account)).toHexString(20);
}
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable account, uint256 amount) internal {
(bool success, ) = account.call{ value: amount }('');
if (!success) revert AddressUtils__SendValueFailed();
}
function functionCall(
address target,
bytes memory data
) internal returns (bytes memory) {
return
functionCall(target, data, 'AddressUtils: failed low-level call');
}
function functionCall(
address target,
bytes memory data,
string memory error
) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, error);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return
functionCallWithValue(
target,
data,
value,
'AddressUtils: failed low-level call with value'
);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory error
) internal returns (bytes memory) {
if (value > address(this).balance)
revert AddressUtils__InsufficientBalance();
return _functionCallWithValue(target, data, value, error);
}
function excessivelySafeCall(
address target,
uint256 gasAmount,
uint256 value,
uint16 maxCopy,
bytes memory data
) internal returns (bool success, bytes memory returnData) {
returnData = new bytes(maxCopy);
assembly {
success := call(
gasAmount,
target,
value,
add(data, 0x20),
mload(data),
0,
0
)
let toCopy := returndatasize()
if gt(toCopy, maxCopy) {
toCopy := maxCopy
}
mstore(returnData, toCopy)
returndatacopy(add(returnData, 0x20), 0, toCopy)
}
}
function _functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory error
) private returns (bytes memory) {
if (!isContract(target)) revert AddressUtils__NotContract();
(bool success, bytes memory returnData) = target.call{ value: value }(
data
);
if (success) {
return returnData;
} else if (returnData.length > 0) {
assembly {
let returnData_size := mload(returnData)
revert(add(32, returnData), returnData_size)
}
} else {
revert(error);
}
}
}
文件 2 的 43:DiamondBase.sol
pragma solidity ^0.8.20;
import { Proxy } from '../../Proxy.sol';
import { IDiamondBase } from './IDiamondBase.sol';
import { DiamondBaseStorage } from './DiamondBaseStorage.sol';
abstract contract DiamondBase is IDiamondBase, Proxy {
function _getImplementation()
internal
view
virtual
override
returns (address implementation)
{
DiamondBaseStorage.Layout storage l;
bytes32 slot = DiamondBaseStorage.STORAGE_SLOT;
assembly {
l.slot := slot
}
implementation = address(bytes20(l.selectorInfo[msg.sig]));
}
}
文件 3 的 43:DiamondBaseStorage.sol
pragma solidity ^0.8.20;
library DiamondBaseStorage {
struct Layout {
mapping(bytes4 => bytes32) selectorInfo;
uint16 selectorCount;
mapping(uint256 => bytes32) selectorSlugs;
address fallbackAddress;
}
bytes32 internal constant STORAGE_SLOT =
keccak256('solidstate.contracts.storage.DiamondBase');
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
文件 4 的 43:DiamondFallback.sol
pragma solidity ^0.8.20;
import { OwnableInternal } from '../../../access/ownable/OwnableInternal.sol';
import { DiamondBase } from '../base/DiamondBase.sol';
import { DiamondBaseStorage } from '../base/DiamondBaseStorage.sol';
import { IDiamondFallback } from './IDiamondFallback.sol';
abstract contract DiamondFallback is
IDiamondFallback,
OwnableInternal,
DiamondBase
{
function getFallbackAddress()
external
view
returns (address fallbackAddress)
{
fallbackAddress = _getFallbackAddress();
}
function setFallbackAddress(address fallbackAddress) external onlyOwner {
_setFallbackAddress(fallbackAddress);
}
function _getImplementation()
internal
view
virtual
override
returns (address implementation)
{
implementation = super._getImplementation();
if (implementation == address(0)) {
implementation = _getFallbackAddress();
}
}
function _getFallbackAddress()
internal
view
virtual
returns (address fallbackAddress)
{
fallbackAddress = DiamondBaseStorage.layout().fallbackAddress;
}
function _setFallbackAddress(address fallbackAddress) internal virtual {
DiamondBaseStorage.layout().fallbackAddress = fallbackAddress;
}
}
文件 5 的 43:DiamondReadable.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondLoupe } from '../../../interfaces/IERC2535DiamondLoupe.sol';
import { DiamondBaseStorage } from '../base/DiamondBaseStorage.sol';
import { IDiamondReadable } from './IDiamondReadable.sol';
import { DiamondReadableInternal } from './DiamondReadableInternal.sol';
abstract contract DiamondReadable is IDiamondReadable, DiamondReadableInternal {
function facets() external view returns (Facet[] memory diamondFacets) {
diamondFacets = _facets();
}
function facetFunctionSelectors(
address facet
) external view returns (bytes4[] memory selectors) {
selectors = _facetFunctionSelectors(facet);
}
function facetAddresses()
external
view
returns (address[] memory addresses)
{
addresses = _facetAddresses();
}
function facetAddress(
bytes4 selector
) external view returns (address facet) {
facet = _facetAddress(selector);
}
}
文件 6 的 43:DiamondReadableInternal.sol
pragma solidity ^0.8.20;
import { DiamondBaseStorage } from '../base/DiamondBaseStorage.sol';
import { IDiamondReadableInternal } from './IDiamondReadableInternal.sol';
abstract contract DiamondReadableInternal is IDiamondReadableInternal {
function _facets() internal view returns (Facet[] memory diamondFacets) {
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
diamondFacets = new Facet[](l.selectorCount);
uint8[] memory numFacetSelectors = new uint8[](l.selectorCount);
uint256 numFacets;
uint256 selectorIndex;
for (uint256 slugIndex; selectorIndex < l.selectorCount; slugIndex++) {
bytes32 slug = l.selectorSlugs[slugIndex];
for (
uint256 slugSelectorIndex;
slugSelectorIndex < 8;
slugSelectorIndex++
) {
selectorIndex++;
if (selectorIndex > l.selectorCount) {
break;
}
bytes4 selector = bytes4(slug << (slugSelectorIndex << 5));
address facet = address(bytes20(l.selectorInfo[selector]));
bool continueLoop;
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
if (diamondFacets[facetIndex].target == facet) {
diamondFacets[facetIndex].selectors[
numFacetSelectors[facetIndex]
] = selector;
require(numFacetSelectors[facetIndex] < 255);
numFacetSelectors[facetIndex]++;
continueLoop = true;
break;
}
}
if (continueLoop) {
continue;
}
diamondFacets[numFacets].target = facet;
diamondFacets[numFacets].selectors = new bytes4[](
l.selectorCount
);
diamondFacets[numFacets].selectors[0] = selector;
numFacetSelectors[numFacets] = 1;
numFacets++;
}
}
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
uint256 numSelectors = numFacetSelectors[facetIndex];
bytes4[] memory selectors = diamondFacets[facetIndex].selectors;
assembly {
mstore(selectors, numSelectors)
}
}
assembly {
mstore(diamondFacets, numFacets)
}
}
function _facetFunctionSelectors(
address facet
) internal view returns (bytes4[] memory selectors) {
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
selectors = new bytes4[](l.selectorCount);
uint256 numSelectors;
uint256 selectorIndex;
for (uint256 slugIndex; selectorIndex < l.selectorCount; slugIndex++) {
bytes32 slug = l.selectorSlugs[slugIndex];
for (
uint256 slugSelectorIndex;
slugSelectorIndex < 8;
slugSelectorIndex++
) {
selectorIndex++;
if (selectorIndex > l.selectorCount) {
break;
}
bytes4 selector = bytes4(slug << (slugSelectorIndex << 5));
if (facet == address(bytes20(l.selectorInfo[selector]))) {
selectors[numSelectors] = selector;
numSelectors++;
}
}
}
assembly {
mstore(selectors, numSelectors)
}
}
function _facetAddresses()
internal
view
returns (address[] memory addresses)
{
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
addresses = new address[](l.selectorCount);
uint256 numFacets;
uint256 selectorIndex;
for (uint256 slugIndex; selectorIndex < l.selectorCount; slugIndex++) {
bytes32 slug = l.selectorSlugs[slugIndex];
for (
uint256 slugSelectorIndex;
slugSelectorIndex < 8;
slugSelectorIndex++
) {
selectorIndex++;
if (selectorIndex > l.selectorCount) {
break;
}
bytes4 selector = bytes4(slug << (slugSelectorIndex << 5));
address facet = address(bytes20(l.selectorInfo[selector]));
bool continueLoop;
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
if (facet == addresses[facetIndex]) {
continueLoop = true;
break;
}
}
if (continueLoop) {
continue;
}
addresses[numFacets] = facet;
numFacets++;
}
}
assembly {
mstore(addresses, numFacets)
}
}
function _facetAddress(
bytes4 selector
) internal view returns (address facet) {
facet = address(
bytes20(DiamondBaseStorage.layout().selectorInfo[selector])
);
}
}
文件 7 的 43:DiamondWritable.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondCut } from '../../../interfaces/IERC2535DiamondCut.sol';
import { OwnableInternal } from '../../../access/ownable/OwnableInternal.sol';
import { IDiamondWritable } from './IDiamondWritable.sol';
import { DiamondWritableInternal } from './DiamondWritableInternal.sol';
abstract contract DiamondWritable is
IDiamondWritable,
DiamondWritableInternal,
OwnableInternal
{
function diamondCut(
FacetCut[] calldata facetCuts,
address target,
bytes calldata data
) external onlyOwner {
_diamondCut(facetCuts, target, data);
}
}
文件 8 的 43:DiamondWritableInternal.sol
pragma solidity ^0.8.20;
import { AddressUtils } from '../../../utils/AddressUtils.sol';
import { DiamondBaseStorage } from '../base/DiamondBaseStorage.sol';
import { IDiamondWritableInternal } from './IDiamondWritableInternal.sol';
abstract contract DiamondWritableInternal is IDiamondWritableInternal {
using AddressUtils for address;
bytes32 private constant CLEAR_ADDRESS_MASK =
bytes32(uint256(0xffffffffffffffffffffffff));
bytes32 private constant CLEAR_SELECTOR_MASK =
bytes32(uint256(0xffffffff << 224));
function _diamondCut(
FacetCut[] memory facetCuts,
address target,
bytes memory data
) internal virtual {
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
unchecked {
uint256 originalSelectorCount = l.selectorCount;
uint256 selectorCount = originalSelectorCount;
bytes32 slug;
if (selectorCount & 7 != 0) {
slug = l.selectorSlugs[selectorCount >> 3];
}
for (uint256 i; i < facetCuts.length; i++) {
FacetCut memory facetCut = facetCuts[i];
FacetCutAction action = facetCut.action;
if (facetCut.selectors.length == 0)
revert DiamondWritable__SelectorNotSpecified();
if (action == FacetCutAction.ADD) {
(selectorCount, slug) = _addFacetSelectors(
l,
facetCut,
selectorCount,
slug
);
} else if (action == FacetCutAction.REPLACE) {
_replaceFacetSelectors(l, facetCut);
} else if (action == FacetCutAction.REMOVE) {
(selectorCount, slug) = _removeFacetSelectors(
l,
facetCut,
selectorCount,
slug
);
}
}
if (selectorCount != originalSelectorCount) {
l.selectorCount = uint16(selectorCount);
}
if (selectorCount & 7 != 0) {
l.selectorSlugs[selectorCount >> 3] = slug;
}
emit DiamondCut(facetCuts, target, data);
_initialize(target, data);
}
}
function _addFacetSelectors(
DiamondBaseStorage.Layout storage l,
FacetCut memory facetCut,
uint256 selectorCount,
bytes32 lastSlug
) internal returns (uint256, bytes32) {
unchecked {
if (facetCut.target.isContract()) {
if (facetCut.target == address(this)) {
revert DiamondWritable__SelectorIsImmutable();
}
} else if (facetCut.target != address(this)) {
revert DiamondWritable__TargetHasNoCode();
}
for (uint256 i; i < facetCut.selectors.length; i++) {
bytes4 selector = facetCut.selectors[i];
if (l.selectorInfo[selector] != bytes32(0))
revert DiamondWritable__SelectorAlreadyAdded();
l.selectorInfo[selector] =
bytes32(selectorCount) |
bytes20(facetCut.target);
uint256 selectorBitIndexInSlug = (selectorCount & 7) << 5;
lastSlug = _insertSelectorIntoSlug(
lastSlug,
selector,
selectorBitIndexInSlug
);
if (selectorBitIndexInSlug == 224) {
l.selectorSlugs[selectorCount >> 3] = lastSlug;
}
selectorCount++;
}
return (selectorCount, lastSlug);
}
}
function _removeFacetSelectors(
DiamondBaseStorage.Layout storage l,
FacetCut memory facetCut,
uint256 selectorCount,
bytes32 lastSlug
) internal returns (uint256, bytes32) {
unchecked {
if (facetCut.target != address(0))
revert DiamondWritable__RemoveTargetNotZeroAddress();
for (uint256 i; i < facetCut.selectors.length; i++) {
selectorCount--;
bytes4 selector = facetCut.selectors[i];
bytes32 selectorInfo = l.selectorInfo[selector];
delete l.selectorInfo[selector];
if (address(bytes20(selectorInfo)) == address(0))
revert DiamondWritable__SelectorNotFound();
if (address(bytes20(selectorInfo)) == address(this))
revert DiamondWritable__SelectorIsImmutable();
if (selectorCount & 7 == 7) {
lastSlug = l.selectorSlugs[selectorCount >> 3];
}
bytes4 lastSelector = bytes4(
lastSlug << ((selectorCount & 7) << 5)
);
if (lastSelector != selector) {
l.selectorInfo[lastSelector] =
(selectorInfo & CLEAR_ADDRESS_MASK) |
bytes20(l.selectorInfo[lastSelector]);
}
uint256 slugIndex = uint16(uint256(selectorInfo)) >> 3;
uint256 selectorBitIndexInSlug = (uint16(
uint256(selectorInfo)
) & 7) << 5;
if (slugIndex == selectorCount >> 3) {
lastSlug = _insertSelectorIntoSlug(
lastSlug,
lastSelector,
selectorBitIndexInSlug
);
} else {
l.selectorSlugs[slugIndex] = _insertSelectorIntoSlug(
l.selectorSlugs[slugIndex],
lastSelector,
selectorBitIndexInSlug
);
}
}
return (selectorCount, lastSlug);
}
}
function _replaceFacetSelectors(
DiamondBaseStorage.Layout storage l,
FacetCut memory facetCut
) internal {
unchecked {
if (!facetCut.target.isContract())
revert DiamondWritable__TargetHasNoCode();
for (uint256 i; i < facetCut.selectors.length; i++) {
bytes4 selector = facetCut.selectors[i];
bytes32 selectorInfo = l.selectorInfo[selector];
address oldFacetAddress = address(bytes20(selectorInfo));
if (oldFacetAddress == address(0))
revert DiamondWritable__SelectorNotFound();
if (oldFacetAddress == address(this))
revert DiamondWritable__SelectorIsImmutable();
if (oldFacetAddress == facetCut.target)
revert DiamondWritable__ReplaceTargetIsIdentical();
l.selectorInfo[selector] =
(selectorInfo & CLEAR_ADDRESS_MASK) |
bytes20(facetCut.target);
}
}
}
function _initialize(address target, bytes memory data) private {
if ((target == address(0)) != (data.length == 0))
revert DiamondWritable__InvalidInitializationParameters();
if (target != address(0)) {
if (target != address(this)) {
if (!target.isContract())
revert DiamondWritable__TargetHasNoCode();
}
(bool success, ) = target.delegatecall(data);
if (!success) {
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
}
}
function _insertSelectorIntoSlug(
bytes32 slug,
bytes4 selector,
uint256 bitIndex
) private pure returns (bytes32) {
return
(slug & ~(CLEAR_SELECTOR_MASK >> bitIndex)) |
(bytes32(selector) >> bitIndex);
}
}
文件 9 的 43:ERC165Base.sol
pragma solidity ^0.8.20;
import { IERC165 } from '../../../interfaces/IERC165.sol';
import { IERC165Base } from './IERC165Base.sol';
import { ERC165BaseInternal } from './ERC165BaseInternal.sol';
import { ERC165BaseStorage } from './ERC165BaseStorage.sol';
abstract contract ERC165Base is IERC165Base, ERC165BaseInternal {
function supportsInterface(bytes4 interfaceId) public view returns (bool) {
return _supportsInterface(interfaceId);
}
}
文件 10 的 43:ERC165BaseInternal.sol
pragma solidity ^0.8.20;
import { IERC165BaseInternal } from './IERC165BaseInternal.sol';
import { ERC165BaseStorage } from './ERC165BaseStorage.sol';
abstract contract ERC165BaseInternal is IERC165BaseInternal {
function _supportsInterface(
bytes4 interfaceId
) internal view virtual returns (bool) {
return ERC165BaseStorage.layout().supportedInterfaces[interfaceId];
}
function _setSupportsInterface(
bytes4 interfaceId,
bool status
) internal virtual {
if (interfaceId == 0xffffffff) revert ERC165Base__InvalidInterfaceId();
ERC165BaseStorage.layout().supportedInterfaces[interfaceId] = status;
}
}
文件 11 的 43:ERC165BaseStorage.sol
pragma solidity ^0.8.20;
library ERC165BaseStorage {
struct Layout {
mapping(bytes4 => bool) supportedInterfaces;
}
bytes32 internal constant STORAGE_SLOT =
keccak256('solidstate.contracts.storage.ERC165Base');
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
文件 12 的 43:IDiamondBase.sol
pragma solidity ^0.8.20;
import { IProxy } from '../../IProxy.sol';
interface IDiamondBase is IProxy {}
文件 13 的 43:IDiamondFallback.sol
pragma solidity ^0.8.20;
import { IDiamondBase } from '../base/IDiamondBase.sol';
interface IDiamondFallback is IDiamondBase {
function getFallbackAddress()
external
view
returns (address fallbackAddress);
function setFallbackAddress(address fallbackAddress) external;
}
文件 14 的 43:IDiamondReadable.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondLoupe } from '../../../interfaces/IERC2535DiamondLoupe.sol';
import { IDiamondReadableInternal } from './IDiamondReadableInternal.sol';
interface IDiamondReadable is IERC2535DiamondLoupe, IDiamondReadableInternal {}
文件 15 的 43:IDiamondReadableInternal.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondLoupeInternal } from '../../../interfaces/IERC2535DiamondLoupeInternal.sol';
interface IDiamondReadableInternal is IERC2535DiamondLoupeInternal {}
文件 16 的 43:IDiamondWritable.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondCut } from '../../../interfaces/IERC2535DiamondCut.sol';
import { IDiamondWritableInternal } from './IDiamondWritableInternal.sol';
interface IDiamondWritable is IERC2535DiamondCut, IDiamondWritableInternal {}
文件 17 的 43:IDiamondWritableInternal.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondCutInternal } from '../../../interfaces/IERC2535DiamondCutInternal.sol';
interface IDiamondWritableInternal is IERC2535DiamondCutInternal {
error DiamondWritable__InvalidInitializationParameters();
error DiamondWritable__RemoveTargetNotZeroAddress();
error DiamondWritable__ReplaceTargetIsIdentical();
error DiamondWritable__SelectorAlreadyAdded();
error DiamondWritable__SelectorIsImmutable();
error DiamondWritable__SelectorNotFound();
error DiamondWritable__SelectorNotSpecified();
error DiamondWritable__TargetHasNoCode();
}
文件 18 的 43:IERC165.sol
pragma solidity ^0.8.20;
import { IERC165Internal } from './IERC165Internal.sol';
interface IERC165 is IERC165Internal {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 19 的 43:IERC165Base.sol
pragma solidity ^0.8.20;
import { IERC165 } from '../../../interfaces/IERC165.sol';
import { IERC165BaseInternal } from './IERC165BaseInternal.sol';
interface IERC165Base is IERC165, IERC165BaseInternal {}
文件 20 的 43:IERC165BaseInternal.sol
pragma solidity ^0.8.20;
import { IERC165Internal } from '../../../interfaces/IERC165Internal.sol';
interface IERC165BaseInternal is IERC165Internal {
error ERC165Base__InvalidInterfaceId();
}
文件 21 的 43:IERC165Internal.sol
pragma solidity ^0.8.20;
interface IERC165Internal {}
文件 22 的 43:IERC173.sol
pragma solidity ^0.8.20;
import { IERC173Internal } from './IERC173Internal.sol';
interface IERC173 is IERC173Internal {
function owner() external view returns (address);
function transferOwnership(address account) external;
}
文件 23 的 43:IERC173Internal.sol
pragma solidity ^0.8.20;
interface IERC173Internal {
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
}
文件 24 的 43:IERC2535DiamondCut.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondCutInternal } from './IERC2535DiamondCutInternal.sol';
interface IERC2535DiamondCut is IERC2535DiamondCutInternal {
function diamondCut(
FacetCut[] calldata facetCuts,
address target,
bytes calldata data
) external;
}
文件 25 的 43:IERC2535DiamondCutInternal.sol
pragma solidity ^0.8.20;
interface IERC2535DiamondCutInternal {
enum FacetCutAction {
ADD,
REPLACE,
REMOVE
}
struct FacetCut {
address target;
FacetCutAction action;
bytes4[] selectors;
}
event DiamondCut(FacetCut[] facetCuts, address target, bytes data);
}
文件 26 的 43:IERC2535DiamondLoupe.sol
pragma solidity ^0.8.20;
import { IERC2535DiamondLoupeInternal } from './IERC2535DiamondLoupeInternal.sol';
interface IERC2535DiamondLoupe is IERC2535DiamondLoupeInternal {
function facets() external view returns (Facet[] memory diamondFacets);
function facetFunctionSelectors(
address facet
) external view returns (bytes4[] memory selectors);
function facetAddresses()
external
view
returns (address[] memory addresses);
function facetAddress(
bytes4 selector
) external view returns (address facet);
}
文件 27 的 43:IERC2535DiamondLoupeInternal.sol
pragma solidity ^0.8.20;
interface IERC2535DiamondLoupeInternal {
struct Facet {
address target;
bytes4[] selectors;
}
}
文件 28 的 43:IOwnable.sol
pragma solidity ^0.8.20;
import { IERC173 } from '../../interfaces/IERC173.sol';
import { IOwnableInternal } from './IOwnableInternal.sol';
interface IOwnable is IOwnableInternal, IERC173 {}
文件 29 的 43:IOwnableInternal.sol
pragma solidity ^0.8.20;
import { IERC173Internal } from '../../interfaces/IERC173Internal.sol';
interface IOwnableInternal is IERC173Internal {
error Ownable__NotOwner();
error Ownable__NotTransitiveOwner();
}
文件 30 的 43:IProxy.sol
pragma solidity ^0.8.20;
interface IProxy {
error Proxy__ImplementationIsNotContract();
fallback() external payable;
}
文件 31 的 43:ISafeOwnable.sol
pragma solidity ^0.8.20;
import { IOwnable } from './IOwnable.sol';
import { ISafeOwnableInternal } from './ISafeOwnableInternal.sol';
interface ISafeOwnable is ISafeOwnableInternal, IOwnable {
function nomineeOwner() external view returns (address);
function acceptOwnership() external;
}
文件 32 的 43:ISafeOwnableInternal.sol
pragma solidity ^0.8.20;
import { IOwnableInternal } from './IOwnableInternal.sol';
interface ISafeOwnableInternal is IOwnableInternal {
error SafeOwnable__NotNomineeOwner();
}
文件 33 的 43:ISolidStateDiamond.sol
pragma solidity ^0.8.20;
import { ISafeOwnable } from '../../access/ownable/ISafeOwnable.sol';
import { IERC165 } from '../../interfaces/IERC165.sol';
import { IDiamondBase } from './base/IDiamondBase.sol';
import { IDiamondFallback } from './fallback/IDiamondFallback.sol';
import { IDiamondReadable } from './readable/IDiamondReadable.sol';
import { IDiamondWritable } from './writable/IDiamondWritable.sol';
interface ISolidStateDiamond is
IDiamondBase,
IDiamondFallback,
IDiamondReadable,
IDiamondWritable,
ISafeOwnable,
IERC165
{
receive() external payable;
}
文件 34 的 43:InvisibleEnemiesDiamond.sol
pragma solidity ^0.8.0;
import "@solidstate/contracts/proxy/diamond/SolidStateDiamond.sol";
contract InvisibleEnemiesDiamond is SolidStateDiamond {
bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.ie.utilitycodiamond.storage");
struct IEDiamondStorage {
address utilityCoDiamond;
}
constructor(address _utilityCoDiamond) {
require(_utilityCoDiamond != address(0), "InvisibleEnemiesDiamond: utilityCoDiamond cannot be the zero address");
IEDiamondStorage storage ds = diamondStorage();
ds.utilityCoDiamond = _utilityCoDiamond;
}
function diamondStorage() internal pure returns (IEDiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
function getUtilityCoDiamond() external view returns (address) {
return diamondStorage().utilityCoDiamond;
}
}
文件 35 的 43:Ownable.sol
pragma solidity ^0.8.20;
import { IERC173 } from '../../interfaces/IERC173.sol';
import { IOwnable } from './IOwnable.sol';
import { OwnableInternal } from './OwnableInternal.sol';
abstract contract Ownable is IOwnable, OwnableInternal {
function owner() public view virtual returns (address) {
return _owner();
}
function transferOwnership(address account) public virtual onlyOwner {
_transferOwnership(account);
}
}
文件 36 的 43:OwnableInternal.sol
pragma solidity ^0.8.20;
import { IERC173 } from '../../interfaces/IERC173.sol';
import { AddressUtils } from '../../utils/AddressUtils.sol';
import { IOwnableInternal } from './IOwnableInternal.sol';
import { OwnableStorage } from './OwnableStorage.sol';
abstract contract OwnableInternal is IOwnableInternal {
using AddressUtils for address;
modifier onlyOwner() {
if (msg.sender != _owner()) revert Ownable__NotOwner();
_;
}
modifier onlyTransitiveOwner() {
if (msg.sender != _transitiveOwner())
revert Ownable__NotTransitiveOwner();
_;
}
function _owner() internal view virtual returns (address) {
return OwnableStorage.layout().owner;
}
function _transitiveOwner() internal view virtual returns (address owner) {
owner = _owner();
while (owner.isContract()) {
try IERC173(owner).owner() returns (address transitiveOwner) {
owner = transitiveOwner;
} catch {
break;
}
}
}
function _transferOwnership(address account) internal virtual {
_setOwner(account);
}
function _setOwner(address account) internal virtual {
OwnableStorage.Layout storage l = OwnableStorage.layout();
emit OwnershipTransferred(l.owner, account);
l.owner = account;
}
}
文件 37 的 43:OwnableStorage.sol
pragma solidity ^0.8.20;
library OwnableStorage {
struct Layout {
address owner;
}
bytes32 internal constant STORAGE_SLOT =
keccak256('solidstate.contracts.storage.Ownable');
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
文件 38 的 43:Proxy.sol
pragma solidity ^0.8.20;
import { AddressUtils } from '../utils/AddressUtils.sol';
import { IProxy } from './IProxy.sol';
abstract contract Proxy is IProxy {
using AddressUtils for address;
fallback() external payable virtual {
address implementation = _getImplementation();
if (!implementation.isContract())
revert Proxy__ImplementationIsNotContract();
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(
gas(),
implementation,
0,
calldatasize(),
0,
0
)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _getImplementation() internal virtual returns (address);
}
文件 39 的 43:SafeOwnable.sol
pragma solidity ^0.8.20;
import { Ownable } from './Ownable.sol';
import { ISafeOwnable } from './ISafeOwnable.sol';
import { OwnableInternal } from './OwnableInternal.sol';
import { SafeOwnableInternal } from './SafeOwnableInternal.sol';
abstract contract SafeOwnable is ISafeOwnable, Ownable, SafeOwnableInternal {
function nomineeOwner() public view virtual returns (address) {
return _nomineeOwner();
}
function acceptOwnership() public virtual onlyNomineeOwner {
_acceptOwnership();
}
function _transferOwnership(
address account
) internal virtual override(OwnableInternal, SafeOwnableInternal) {
super._transferOwnership(account);
}
}
文件 40 的 43:SafeOwnableInternal.sol
pragma solidity ^0.8.20;
import { ISafeOwnableInternal } from './ISafeOwnableInternal.sol';
import { OwnableInternal } from './OwnableInternal.sol';
import { SafeOwnableStorage } from './SafeOwnableStorage.sol';
abstract contract SafeOwnableInternal is ISafeOwnableInternal, OwnableInternal {
modifier onlyNomineeOwner() {
if (msg.sender != _nomineeOwner())
revert SafeOwnable__NotNomineeOwner();
_;
}
function _nomineeOwner() internal view virtual returns (address) {
return SafeOwnableStorage.layout().nomineeOwner;
}
function _acceptOwnership() internal virtual {
_setOwner(msg.sender);
delete SafeOwnableStorage.layout().nomineeOwner;
}
function _transferOwnership(address account) internal virtual override {
_setNomineeOwner(account);
}
function _setNomineeOwner(address account) internal virtual {
SafeOwnableStorage.layout().nomineeOwner = account;
}
}
文件 41 的 43:SafeOwnableStorage.sol
pragma solidity ^0.8.20;
library SafeOwnableStorage {
struct Layout {
address nomineeOwner;
}
bytes32 internal constant STORAGE_SLOT =
keccak256('solidstate.contracts.storage.SafeOwnable');
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
文件 42 的 43:SolidStateDiamond.sol
pragma solidity ^0.8.20;
import { IOwnable, Ownable, OwnableInternal } from '../../access/ownable/Ownable.sol';
import { ISafeOwnable, SafeOwnable } from '../../access/ownable/SafeOwnable.sol';
import { IERC165 } from '../../interfaces/IERC165.sol';
import { IERC173 } from '../../interfaces/IERC173.sol';
import { IERC2535DiamondCut } from '../../interfaces/IERC2535DiamondCut.sol';
import { IERC2535DiamondLoupe } from '../../interfaces/IERC2535DiamondLoupe.sol';
import { ERC165Base, ERC165BaseStorage } from '../../introspection/ERC165/base/ERC165Base.sol';
import { DiamondBase } from './base/DiamondBase.sol';
import { DiamondFallback, IDiamondFallback } from './fallback/DiamondFallback.sol';
import { DiamondReadable } from './readable/DiamondReadable.sol';
import { DiamondWritable } from './writable/DiamondWritable.sol';
import { ISolidStateDiamond } from './ISolidStateDiamond.sol';
abstract contract SolidStateDiamond is
ISolidStateDiamond,
DiamondBase,
DiamondFallback,
DiamondReadable,
DiamondWritable,
SafeOwnable,
ERC165Base
{
constructor() {
bytes4[] memory selectors = new bytes4[](12);
uint256 selectorIndex;
selectors[selectorIndex++] = IDiamondFallback
.getFallbackAddress
.selector;
selectors[selectorIndex++] = IDiamondFallback
.setFallbackAddress
.selector;
_setSupportsInterface(type(IDiamondFallback).interfaceId, true);
selectors[selectorIndex++] = IERC2535DiamondCut.diamondCut.selector;
_setSupportsInterface(type(IERC2535DiamondCut).interfaceId, true);
selectors[selectorIndex++] = IERC2535DiamondLoupe.facets.selector;
selectors[selectorIndex++] = IERC2535DiamondLoupe
.facetFunctionSelectors
.selector;
selectors[selectorIndex++] = IERC2535DiamondLoupe
.facetAddresses
.selector;
selectors[selectorIndex++] = IERC2535DiamondLoupe.facetAddress.selector;
_setSupportsInterface(type(IERC2535DiamondLoupe).interfaceId, true);
selectors[selectorIndex++] = IERC165.supportsInterface.selector;
_setSupportsInterface(type(IERC165).interfaceId, true);
selectors[selectorIndex++] = Ownable.owner.selector;
selectors[selectorIndex++] = SafeOwnable.nomineeOwner.selector;
selectors[selectorIndex++] = Ownable.transferOwnership.selector;
selectors[selectorIndex++] = SafeOwnable.acceptOwnership.selector;
_setSupportsInterface(type(IERC173).interfaceId, true);
FacetCut[] memory facetCuts = new FacetCut[](1);
facetCuts[0] = FacetCut({
target: address(this),
action: FacetCutAction.ADD,
selectors: selectors
});
_diamondCut(facetCuts, address(0), '');
_setOwner(msg.sender);
}
receive() external payable {}
function _transferOwnership(
address account
) internal virtual override(OwnableInternal, SafeOwnable) {
super._transferOwnership(account);
}
function _getImplementation()
internal
view
override(DiamondBase, DiamondFallback)
returns (address implementation)
{
implementation = super._getImplementation();
}
}
文件 43 的 43:UintUtils.sol
pragma solidity ^0.8.20;
library UintUtils {
error UintUtils__InsufficientPadding();
error UintUtils__InvalidBase();
bytes16 private constant HEX_SYMBOLS = '0123456789abcdef';
function add(uint256 a, int256 b) internal pure returns (uint256) {
return b < 0 ? sub(a, -b) : a + uint256(b);
}
function sub(uint256 a, int256 b) internal pure returns (uint256) {
return b < 0 ? add(a, -b) : a - uint256(b);
}
function toString(
uint256 value,
uint256 radix
) internal pure returns (string memory output) {
if (radix < 2) {
revert UintUtils__InvalidBase();
}
uint256 length;
uint256 temp = value;
do {
unchecked {
length++;
}
temp /= radix;
} while (temp != 0);
output = toString(value, radix, length);
}
function toString(
uint256 value,
uint256 radix,
uint256 length
) internal pure returns (string memory output) {
if (radix < 2 || radix > 36) {
revert UintUtils__InvalidBase();
}
bytes memory buffer = new bytes(length);
while (length != 0) {
unchecked {
length--;
}
uint256 char = value % radix;
if (char < 10) {
char |= 48;
} else {
unchecked {
char += 87;
}
}
buffer[length] = bytes1(uint8(char));
value /= radix;
}
if (value != 0) revert UintUtils__InsufficientPadding();
output = string(buffer);
}
function toBinString(
uint256 value
) internal pure returns (string memory output) {
uint256 length;
uint256 temp = value;
do {
unchecked {
length++;
}
temp >>= 1;
} while (temp != 0);
output = toBinString(value, length);
}
function toBinString(
uint256 value,
uint256 length
) internal pure returns (string memory output) {
length += 2;
bytes memory buffer = new bytes(length);
buffer[0] = '0';
buffer[1] = 'b';
while (length > 2) {
unchecked {
length--;
}
buffer[length] = HEX_SYMBOLS[value & 1];
value >>= 1;
}
if (value != 0) revert UintUtils__InsufficientPadding();
output = string(buffer);
}
function toOctString(
uint256 value
) internal pure returns (string memory output) {
uint256 length;
uint256 temp = value;
do {
unchecked {
length++;
}
temp >>= 3;
} while (temp != 0);
output = toOctString(value, length);
}
function toOctString(
uint256 value,
uint256 length
) internal pure returns (string memory output) {
length += 2;
bytes memory buffer = new bytes(length);
buffer[0] = '0';
buffer[1] = 'o';
while (length > 2) {
unchecked {
length--;
}
buffer[length] = HEX_SYMBOLS[value & 7];
value >>= 3;
}
if (value != 0) revert UintUtils__InsufficientPadding();
output = string(buffer);
}
function toDecString(
uint256 value
) internal pure returns (string memory output) {
output = toString(value, 10);
}
function toDecString(
uint256 value,
uint256 length
) internal pure returns (string memory output) {
output = toString(value, 10, length);
}
function toHexString(
uint256 value
) internal pure returns (string memory output) {
uint256 length;
uint256 temp = value;
do {
unchecked {
length++;
}
temp >>= 8;
} while (temp != 0);
output = toHexString(value, length);
}
function toHexString(
uint256 value,
uint256 length
) internal pure returns (string memory output) {
unchecked {
length = (length << 1) + 2;
}
bytes memory buffer = new bytes(length);
buffer[0] = '0';
buffer[1] = 'x';
while (length > 2) {
unchecked {
length--;
}
buffer[length] = HEX_SYMBOLS[value & 15];
value >>= 4;
}
if (value != 0) revert UintUtils__InsufficientPadding();
output = string(buffer);
}
}
{
"compilationTarget": {
"InvisibleEnemiesDiamond.sol": "InvisibleEnemiesDiamond"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_utilityCoDiamond","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DiamondWritable__InvalidInitializationParameters","type":"error"},{"inputs":[],"name":"DiamondWritable__RemoveTargetNotZeroAddress","type":"error"},{"inputs":[],"name":"DiamondWritable__ReplaceTargetIsIdentical","type":"error"},{"inputs":[],"name":"DiamondWritable__SelectorAlreadyAdded","type":"error"},{"inputs":[],"name":"DiamondWritable__SelectorIsImmutable","type":"error"},{"inputs":[],"name":"DiamondWritable__SelectorNotFound","type":"error"},{"inputs":[],"name":"DiamondWritable__SelectorNotSpecified","type":"error"},{"inputs":[],"name":"DiamondWritable__TargetHasNoCode","type":"error"},{"inputs":[],"name":"ERC165Base__InvalidInterfaceId","type":"error"},{"inputs":[],"name":"Ownable__NotOwner","type":"error"},{"inputs":[],"name":"Ownable__NotTransitiveOwner","type":"error"},{"inputs":[],"name":"Proxy__ImplementationIsNotContract","type":"error"},{"inputs":[],"name":"SafeOwnable__NotNomineeOwner","type":"error"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"enum IERC2535DiamondCutInternal.FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"indexed":false,"internalType":"struct IERC2535DiamondCutInternal.FacetCut[]","name":"facetCuts","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"DiamondCut","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"enum IERC2535DiamondCutInternal.FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"internalType":"struct IERC2535DiamondCutInternal.FacetCut[]","name":"facetCuts","type":"tuple[]"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"diamondCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"facetAddress","outputs":[{"internalType":"address","name":"facet","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"facetAddresses","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"facet","type":"address"}],"name":"facetFunctionSelectors","outputs":[{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"facets","outputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"internalType":"struct IERC2535DiamondLoupeInternal.Facet[]","name":"diamondFacets","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFallbackAddress","outputs":[{"internalType":"address","name":"fallbackAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUtilityCoDiamond","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nomineeOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"fallbackAddress","type":"address"}],"name":"setFallbackAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]