This contract's source code is verified! Compiler
0.8.20+commit.a1b79de6
File 1 of 51: AccessControlInternal.sol
pragma solidity ^0.8.0;
import { EnumerableSet } from '../../data/EnumerableSet.sol' ;
import { AddressUtils } from '../../utils/AddressUtils.sol' ;
import { UintUtils } from '../../utils/UintUtils.sol' ;
import { IAccessControlInternal } from './IAccessControlInternal.sol' ;
import { AccessControlStorage } from './AccessControlStorage.sol' ;
abstract contract AccessControlInternal is IAccessControlInternal {
using AddressUtils for address ;
using EnumerableSet for EnumerableSet .AddressSet ;
using UintUtils for uint256 ;
modifier onlyRole (bytes32 role ) {
_checkRole(role);
_ ;
}
function _hasRole (
bytes32 role,
address account
) internal view virtual returns (bool ) {
return
AccessControlStorage.layout().roles[role].members.contains(account);
}
function _checkRole (bytes32 role ) internal view virtual {
_checkRole(role, msg .sender );
}
function _checkRole (bytes32 role, address account ) internal view virtual {
if (! _hasRole(role, account)) {
revert (
string (
abi .encodePacked (
'AccessControl: account ' ,
account.toString(),
' is missing role ' ,
uint256 (role).toHexString(32 )
)
)
);
}
}
function _getRoleAdmin (
bytes32 role
) internal view virtual returns (bytes32 ) {
return AccessControlStorage.layout().roles[role].adminRole;
}
function _setRoleAdmin (bytes32 role, bytes32 adminRole ) internal virtual {
bytes32 previousAdminRole = _getRoleAdmin(role);
AccessControlStorage.layout().roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole (bytes32 role, address account ) internal virtual {
AccessControlStorage.layout().roles[role].members.add(account);
emit RoleGranted(role, account, msg .sender );
}
function _revokeRole (bytes32 role, address account ) internal virtual {
AccessControlStorage.layout().roles[role].members.remove(account);
emit RoleRevoked(role, account, msg .sender );
}
function _renounceRole (bytes32 role ) internal virtual {
_revokeRole(role, msg .sender );
}
function _getRoleMember (
bytes32 role,
uint256 index
) internal view virtual returns (address ) {
return AccessControlStorage.layout().roles[role].members.at(index);
}
function _getRoleMemberCount (
bytes32 role
) internal view virtual returns (uint256 ) {
return AccessControlStorage.layout().roles[role].members.length ();
}
}
File 2 of 51: AccessControlStorage.sol
pragma solidity ^0.8.0;
import { EnumerableSet } from '../../data/EnumerableSet.sol' ;
library AccessControlStorage {
struct RoleData {
EnumerableSet.AddressSet members;
bytes32 adminRole;
}
struct Layout {
mapping (bytes32 = > RoleData) roles;
}
bytes32 internal constant DEFAULT_ADMIN_ROLE = 0x00 ;
bytes32 internal constant STORAGE_SLOT =
keccak256 ('solidstate.contracts.storage.AccessControl' );
function layout ( ) internal pure returns (Layout storage l ) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
File 3 of 51: AddressUtils.sol
pragma solidity ^0.8.8;
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 ) ;
}
}
}
File 4 of 51: DiamondBase.sol
pragma solidity ^0.8.8;
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.facets[msg .sig ]));
}
}
File 5 of 51: DiamondBaseStorage.sol
pragma solidity ^0.8.8;
library DiamondBaseStorage {
struct Layout {
mapping (bytes4 = > bytes32 ) facets;
uint16 selectorCount;
mapping (uint256 = > bytes32 ) selectorSlots;
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
}
}
}
File 6 of 51: DiamondFallback.sol
pragma solidity ^0.8.8;
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;
}
}
File 7 of 51: DiamondReadable.sol
pragma solidity ^0.8.8;
import { DiamondBaseStorage } from '../base/DiamondBaseStorage.sol' ;
import { IDiamondReadable } from './IDiamondReadable.sol' ;
abstract contract DiamondReadable is IDiamondReadable {
function facets ( ) external 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 slotIndex; selectorIndex < l.selectorCount; slotIndex+ + ) {
bytes32 slot = l.selectorSlots[slotIndex];
for (
uint256 selectorSlotIndex;
selectorSlotIndex < 8 ;
selectorSlotIndex+ +
) {
selectorIndex+ + ;
if (selectorIndex > l.selectorCount) {
break ;
}
bytes4 selector = bytes4 (slot < < (selectorSlotIndex < < 5 ));
address facet = address (bytes20 (l.facets[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
) external view returns (bytes4 [] memory selectors ) {
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
selectors = new bytes4 [](l.selectorCount);
uint256 numSelectors;
uint256 selectorIndex;
for (uint256 slotIndex; selectorIndex < l.selectorCount; slotIndex+ + ) {
bytes32 slot = l.selectorSlots[slotIndex];
for (
uint256 selectorSlotIndex;
selectorSlotIndex < 8 ;
selectorSlotIndex+ +
) {
selectorIndex+ + ;
if (selectorIndex > l.selectorCount) {
break ;
}
bytes4 selector = bytes4 (slot < < (selectorSlotIndex < < 5 ));
if (facet = = address (bytes20 (l.facets[selector]))) {
selectors[numSelectors] = selector;
numSelectors+ + ;
}
}
}
assembly {
mstore (selectors, numSelectors)
}
}
function facetAddresses ( )
external
view
returns (address [] memory addresses )
{
DiamondBaseStorage.Layout storage l = DiamondBaseStorage.layout();
addresses = new address [](l.selectorCount);
uint256 numFacets;
uint256 selectorIndex;
for (uint256 slotIndex; selectorIndex < l.selectorCount; slotIndex+ + ) {
bytes32 slot = l.selectorSlots[slotIndex];
for (
uint256 selectorSlotIndex;
selectorSlotIndex < 8 ;
selectorSlotIndex+ +
) {
selectorIndex+ + ;
if (selectorIndex > l.selectorCount) {
break ;
}
bytes4 selector = bytes4 (slot < < (selectorSlotIndex < < 5 ));
address facet = address (bytes20 (l.facets[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
) external view returns (address facet ) {
facet = address (bytes20 (DiamondBaseStorage.layout().facets[selector]));
}
}
File 8 of 51: DiamondWritable.sol
pragma solidity ^0.8.8;
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);
}
}
File 9 of 51: DiamondWritableInternal.sol
pragma solidity ^0.8.0;
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 selectorSlot;
if (selectorCount & 7 > 0 ) {
selectorSlot = l.selectorSlots[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, selectorSlot) = _addFacetSelectors(
l,
selectorCount,
selectorSlot,
facetCut
);
} else if (action = = FacetCutAction.REPLACE) {
_replaceFacetSelectors(l, facetCut);
} else if (action = = FacetCutAction.REMOVE) {
(selectorCount, selectorSlot) = _removeFacetSelectors(
l,
selectorCount,
selectorSlot,
facetCut
);
}
}
if (selectorCount ! = originalSelectorCount) {
l.selectorCount = uint16 (selectorCount);
}
if (selectorCount & 7 > 0 ) {
l.selectorSlots[selectorCount > > 3 ] = selectorSlot;
}
emit DiamondCut(facetCuts, target, data);
_initialize(target, data);
}
}
function _addFacetSelectors (
DiamondBaseStorage.Layout storage l,
uint256 selectorCount,
bytes32 selectorSlot,
FacetCut memory facetCut
) internal returns (uint256 , bytes32 ) {
unchecked {
if (
facetCut.target ! = address (this ) & &
! facetCut.target.isContract()
) revert DiamondWritable__TargetHasNoCode();
for (uint256 i; i < facetCut.selectors.length ; i+ + ) {
bytes4 selector = facetCut.selectors[i];
bytes32 oldFacet = l.facets[selector];
if (address (bytes20 (oldFacet)) ! = address (0 ))
revert DiamondWritable__SelectorAlreadyAdded();
l.facets[selector] =
bytes20 (facetCut.target) |
bytes32 (selectorCount);
uint256 selectorInSlotPosition = (selectorCount & 7 ) < < 5 ;
selectorSlot =
(selectorSlot &
~ (CLEAR_SELECTOR_MASK > > selectorInSlotPosition)) |
(bytes32 (selector) > > selectorInSlotPosition);
if (selectorInSlotPosition = = 224 ) {
l.selectorSlots[selectorCount > > 3 ] = selectorSlot;
selectorSlot = 0 ;
}
selectorCount+ + ;
}
return (selectorCount, selectorSlot);
}
}
function _removeFacetSelectors (
DiamondBaseStorage.Layout storage l,
uint256 selectorCount,
bytes32 selectorSlot,
FacetCut memory facetCut
) internal returns (uint256 , bytes32 ) {
unchecked {
if (facetCut.target ! = address (0 ))
revert DiamondWritable__RemoveTargetNotZeroAddress();
uint256 selectorSlotCount = selectorCount > > 3 ;
uint256 selectorInSlotIndex = selectorCount & 7 ;
for (uint256 i; i < facetCut.selectors.length ; i+ + ) {
bytes4 selector = facetCut.selectors[i];
bytes32 oldFacet = l.facets[selector];
if (address (bytes20 (oldFacet)) = = address (0 ))
revert DiamondWritable__SelectorNotFound();
if (address (bytes20 (oldFacet)) = = address (this ))
revert DiamondWritable__SelectorIsImmutable();
if (selectorSlot = = 0 ) {
selectorSlotCount- - ;
selectorSlot = l.selectorSlots[selectorSlotCount];
selectorInSlotIndex = 7 ;
} else {
selectorInSlotIndex- - ;
}
bytes4 lastSelector;
uint256 oldSelectorsSlotCount;
uint256 oldSelectorInSlotPosition;
{
lastSelector = bytes4 (
selectorSlot < < (selectorInSlotIndex < < 5 )
);
if (lastSelector ! = selector) {
l.facets[lastSelector] =
(oldFacet & CLEAR_ADDRESS_MASK) |
bytes20 (l.facets[lastSelector]);
}
delete l.facets[selector];
uint256 oldSelectorCount = uint16 (uint256 (oldFacet));
oldSelectorsSlotCount = oldSelectorCount > > 3 ;
oldSelectorInSlotPosition = (oldSelectorCount & 7 ) < < 5 ;
}
if (oldSelectorsSlotCount ! = selectorSlotCount) {
bytes32 oldSelectorSlot = l.selectorSlots[
oldSelectorsSlotCount
];
oldSelectorSlot =
(oldSelectorSlot &
~ (CLEAR_SELECTOR_MASK > >
oldSelectorInSlotPosition)) |
(bytes32 (lastSelector) > > oldSelectorInSlotPosition);
l.selectorSlots[oldSelectorsSlotCount] = oldSelectorSlot;
} else {
selectorSlot =
(selectorSlot &
~ (CLEAR_SELECTOR_MASK > >
oldSelectorInSlotPosition)) |
(bytes32 (lastSelector) > > oldSelectorInSlotPosition);
}
if (selectorInSlotIndex = = 0 ) {
delete l.selectorSlots[selectorSlotCount];
selectorSlot = 0 ;
}
}
selectorCount = (selectorSlotCount < < 3 ) | selectorInSlotIndex;
return (selectorCount, selectorSlot);
}
}
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 oldFacet = l.facets[selector];
address oldFacetAddress = address (bytes20 (oldFacet));
if (oldFacetAddress = = address (0 ))
revert DiamondWritable__SelectorNotFound();
if (oldFacetAddress = = address (this ))
revert DiamondWritable__SelectorIsImmutable();
if (oldFacetAddress = = facetCut.target)
revert DiamondWritable__ReplaceTargetIsIdentical();
l.facets[selector] =
(oldFacet & 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 ())
}
}
}
}
}
File 10 of 51: ERC165Base.sol
pragma solidity ^0.8.8;
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);
}
}
File 11 of 51: ERC165BaseInternal.sol
pragma solidity ^0.8.8;
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;
}
}
File 12 of 51: ERC165BaseStorage.sol
pragma solidity ^0.8.8;
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
}
}
}
File 13 of 51: ERC2981.sol
pragma solidity ^0.8.8;
import { IERC2981 } from '../../../interfaces/IERC2981.sol' ;
import { ERC2981Storage } from './ERC2981Storage.sol' ;
import { ERC2981Internal } from './ERC2981Internal.sol' ;
abstract contract ERC2981 is IERC2981 , ERC2981Internal {
function royaltyInfo (
uint256 tokenId,
uint256 salePrice
) external view returns (address , uint256 ) {
return _royaltyInfo(tokenId, salePrice);
}
}
File 14 of 51: ERC2981Internal.sol
pragma solidity ^0.8.8;
import { ERC2981Storage } from './ERC2981Storage.sol' ;
import { IERC2981Internal } from '../../../interfaces/IERC2981Internal.sol' ;
abstract contract ERC2981Internal is IERC2981Internal {
function _royaltyInfo (
uint256 tokenId,
uint256 salePrice
) internal view virtual returns (address royaltyReceiver, uint256 royalty ) {
uint256 royaltyBPS = _getRoyaltyBPS(tokenId);
return (_getRoyaltyReceiver(tokenId), (royaltyBPS * salePrice) / 10000 );
}
function _getRoyaltyBPS (
uint256 tokenId
) internal view virtual returns (uint16 royaltyBPS ) {
ERC2981Storage.Layout storage l = ERC2981Storage.layout();
royaltyBPS = l.royaltiesBPS[tokenId];
if (royaltyBPS = = 0 ) {
royaltyBPS = l.defaultRoyaltyBPS;
}
}
function _getRoyaltyReceiver (
uint256 tokenId
) internal view virtual returns (address royaltyReceiver ) {
ERC2981Storage.Layout storage l = ERC2981Storage.layout();
royaltyReceiver = l.royaltyReceivers[tokenId];
if (royaltyReceiver = = address (0 )) {
royaltyReceiver = l.defaultRoyaltyReceiver;
}
}
}
File 15 of 51: ERC2981Storage.sol
pragma solidity ^0.8.8;
library ERC2981Storage {
struct Layout {
mapping (uint256 = > uint16 ) royaltiesBPS;
uint16 defaultRoyaltyBPS;
mapping (uint256 = > address ) royaltyReceivers;
address defaultRoyaltyReceiver;
}
bytes32 internal constant STORAGE_SLOT =
keccak256 ('solidstate.contracts.storage.ERC2981' );
function layout ( ) internal pure returns (Layout storage l ) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
File 16 of 51: ERC721MetadataStorage.sol
pragma solidity ^0.8.8;
library ERC721MetadataStorage {
bytes32 internal constant STORAGE_SLOT =
keccak256 ('solidstate.contracts.storage.ERC721Metadata' );
struct Layout {
string name;
string symbol;
string baseURI;
mapping (uint256 = > string ) tokenURIs;
}
function layout ( ) internal pure returns (Layout storage l ) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
File 17 of 51: EnumerableSet.sol
pragma solidity ^0.8.8;
library EnumerableSet {
error EnumerableSet__IndexOutOfBounds ( ) ;
struct Set {
bytes32 [] _values;
mapping (bytes32 = > uint256 ) _indexes;
}
struct Bytes32Set {
Set _inner;
}
struct AddressSet {
Set _inner;
}
struct UintSet {
Set _inner;
}
function at (
Bytes32Set storage set,
uint256 index
) internal view returns (bytes32 ) {
return _at(set._inner, index);
}
function at (
AddressSet storage set,
uint256 index
) internal view returns (address ) {
return address (uint160 (uint256 (_at(set._inner, index))));
}
function at (
UintSet storage set,
uint256 index
) internal view returns (uint256 ) {
return uint256 (_at(set._inner, index));
}
function contains (
Bytes32Set storage set,
bytes32 value
) internal view returns (bool ) {
return _contains(set._inner, value);
}
function contains (
AddressSet storage set,
address value
) internal view returns (bool ) {
return _contains(set._inner, bytes32 (uint256 (uint160 (value))));
}
function contains (
UintSet storage set,
uint256 value
) internal view returns (bool ) {
return _contains(set._inner, bytes32 (value));
}
function indexOf (
Bytes32Set storage set,
bytes32 value
) internal view returns (uint256 ) {
return _indexOf(set._inner, value);
}
function indexOf (
AddressSet storage set,
address value
) internal view returns (uint256 ) {
return _indexOf(set._inner, bytes32 (uint256 (uint160 (value))));
}
function indexOf (
UintSet storage set,
uint256 value
) internal view returns (uint256 ) {
return _indexOf(set._inner, bytes32 (value));
}
function length (Bytes32Set storage set ) internal view returns (uint256 ) {
return _length(set._inner);
}
function length (AddressSet storage set ) internal view returns (uint256 ) {
return _length(set._inner);
}
function length (UintSet storage set ) internal view returns (uint256 ) {
return _length(set._inner);
}
function add (
Bytes32Set storage set,
bytes32 value
) internal returns (bool ) {
return _add(set._inner, value);
}
function add (
AddressSet storage set,
address value
) internal returns (bool ) {
return _add(set._inner, bytes32 (uint256 (uint160 (value))));
}
function add (UintSet storage set, uint256 value ) internal returns (bool ) {
return _add(set._inner, bytes32 (value));
}
function remove (
Bytes32Set storage set,
bytes32 value
) internal returns (bool ) {
return _remove(set._inner, value);
}
function remove (
AddressSet storage set,
address value
) internal returns (bool ) {
return _remove(set._inner, bytes32 (uint256 (uint160 (value))));
}
function remove (
UintSet storage set,
uint256 value
) internal returns (bool ) {
return _remove(set._inner, bytes32 (value));
}
function toArray (
Bytes32Set storage set
) internal view returns (bytes32 [] memory ) {
return set._inner._values;
}
function toArray (
AddressSet storage set
) internal view returns (address [] memory ) {
bytes32 [] storage values = set._inner._values;
address [] storage array;
assembly {
array.slot := values.slot
}
return array;
}
function toArray (
UintSet storage set
) internal view returns (uint256 [] memory ) {
bytes32 [] storage values = set._inner._values;
uint256 [] storage array;
assembly {
array.slot := values.slot
}
return array;
}
function _at (
Set storage set,
uint256 index
) private view returns (bytes32 ) {
if (index > = set._values.length )
revert EnumerableSet__IndexOutOfBounds();
return set._values[index];
}
function _contains (
Set storage set,
bytes32 value
) private view returns (bool ) {
return set._indexes[value] ! = 0 ;
}
function _indexOf (
Set storage set,
bytes32 value
) private view returns (uint256 ) {
unchecked {
return set._indexes[value] - 1 ;
}
}
function _length (Set storage set ) private view returns (uint256 ) {
return set._values.length ;
}
function _add (
Set storage set,
bytes32 value
) private returns (bool status ) {
if (! _contains(set, value)) {
set._values.push (value);
set._indexes[value] = set._values.length ;
status = true ;
}
}
function _remove (
Set storage set,
bytes32 value
) private returns (bool status ) {
uint256 valueIndex = set._indexes[value];
if (valueIndex ! = 0 ) {
unchecked {
bytes32 last = set._values[set._values.length - 1 ];
set._values[valueIndex - 1 ] = last;
set._indexes[last] = valueIndex;
}
set._values.pop ();
delete set._indexes[value];
status = true ;
}
}
}
File 18 of 51: IAccessControlInternal.sol
pragma solidity ^0.8.0;
interface IAccessControlInternal {
event RoleAdminChanged (
bytes32 indexed role,
bytes32 indexed previousAdminRole,
bytes32 indexed newAdminRole
) ;
event RoleGranted (
bytes32 indexed role,
address indexed account,
address indexed sender
) ;
event RoleRevoked (
bytes32 indexed role,
address indexed account,
address indexed sender
) ;
}
File 19 of 51: IDiamondBase.sol
pragma solidity ^0.8.8;
import { IProxy } from '../../IProxy.sol' ;
interface IDiamondBase is IProxy {}
File 20 of 51: IDiamondFallback.sol
pragma solidity ^0.8.8;
import { IDiamondBase } from '../base/IDiamondBase.sol' ;
interface IDiamondFallback is IDiamondBase {
function getFallbackAddress ( )
external
view
returns (address fallbackAddress ) ;
function setFallbackAddress (address fallbackAddress ) external ;
}
File 21 of 51: IDiamondReadable.sol
pragma solidity ^0.8.8;
interface IDiamondReadable {
struct Facet {
address target;
bytes4 [] selectors;
}
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 ) ;
}
File 22 of 51: IDiamondWritable.sol
pragma solidity ^0.8.8;
import { IDiamondWritableInternal } from './IDiamondWritableInternal.sol' ;
interface IDiamondWritable is IDiamondWritableInternal {
function diamondCut (
FacetCut[] calldata facetCuts,
address target,
bytes calldata data
) external ;
}
File 23 of 51: IDiamondWritableInternal.sol
pragma solidity ^0.8.8;
interface IDiamondWritableInternal {
enum FacetCutAction {
ADD,
REPLACE,
REMOVE
}
event DiamondCut (FacetCut[] facetCuts, address target, bytes data ) ;
error DiamondWritable__InvalidInitializationParameters ( ) ;
error DiamondWritable__RemoveTargetNotZeroAddress ( ) ;
error DiamondWritable__ReplaceTargetIsIdentical ( ) ;
error DiamondWritable__SelectorAlreadyAdded ( ) ;
error DiamondWritable__SelectorIsImmutable ( ) ;
error DiamondWritable__SelectorNotFound ( ) ;
error DiamondWritable__SelectorNotSpecified ( ) ;
error DiamondWritable__TargetHasNoCode ( ) ;
struct FacetCut {
address target;
FacetCutAction action;
bytes4 [] selectors;
}
}
File 24 of 51: IERC165.sol
pragma solidity ^0.8.8;
import { IERC165Internal } from './IERC165Internal.sol' ;
interface IERC165 is IERC165Internal {
function supportsInterface (bytes4 interfaceId ) external view returns (bool ) ;
}
File 25 of 51: IERC165Base.sol
pragma solidity ^0.8.0;
import { IERC165 } from '../../../interfaces/IERC165.sol' ;
import { IERC165BaseInternal } from './IERC165BaseInternal.sol' ;
interface IERC165Base is IERC165 , IERC165BaseInternal {}
File 26 of 51: IERC165BaseInternal.sol
pragma solidity ^0.8.0;
import { IERC165Internal } from '../../../interfaces/IERC165Internal.sol' ;
interface IERC165BaseInternal is IERC165Internal {
error ERC165Base__InvalidInterfaceId ( ) ;
}
File 27 of 51: IERC165Internal.sol
pragma solidity ^0.8.8;
interface IERC165Internal {
}
File 28 of 51: IERC173.sol
pragma solidity ^0.8.8;
import { IERC173Internal } from './IERC173Internal.sol' ;
interface IERC173 is IERC173Internal {
function owner ( ) external view returns (address ) ;
function transferOwnership (address account ) external ;
}
File 29 of 51: IERC173Internal.sol
pragma solidity ^0.8.8;
interface IERC173Internal {
event OwnershipTransferred (
address indexed previousOwner,
address indexed newOwner
) ;
}
File 30 of 51: IERC2981.sol
pragma solidity ^0.8.8;
import { IERC165 } from './IERC165.sol' ;
import { IERC2981Internal } from './IERC2981Internal.sol' ;
interface IERC2981 is IERC2981Internal , IERC165 {
function royaltyInfo (
uint256 tokenId,
uint256 salePrice
) external view returns (address receiever, uint256 royaltyAmount ) ;
}
File 31 of 51: IERC2981Internal.sol
pragma solidity ^0.8.8;
interface IERC2981Internal {
}
File 32 of 51: IOwnable.sol
pragma solidity ^0.8.8;
import { IERC173 } from '../../interfaces/IERC173.sol' ;
import { IOwnableInternal } from './IOwnableInternal.sol' ;
interface IOwnable is IOwnableInternal , IERC173 {}
File 33 of 51: IOwnableInternal.sol
pragma solidity ^0.8.8;
import { IERC173Internal } from '../../interfaces/IERC173Internal.sol' ;
interface IOwnableInternal is IERC173Internal {
error Ownable__NotOwner ( ) ;
error Ownable__NotTransitiveOwner ( ) ;
}
File 34 of 51: IPausableInternal.sol
pragma solidity ^0.8.8;
interface IPausableInternal {
error Pausable__Paused ( ) ;
error Pausable__NotPaused ( ) ;
event Paused (address account ) ;
event Unpaused (address account ) ;
}
File 35 of 51: IProxy.sol
pragma solidity ^0.8.8;
interface IProxy {
error Proxy__ImplementationIsNotContract ( ) ;
fallback ( ) external payable ;
}
File 36 of 51: ISafeOwnable.sol
pragma solidity ^0.8.8;
import { IOwnable } from './IOwnable.sol' ;
import { ISafeOwnableInternal } from './ISafeOwnableInternal.sol' ;
interface ISafeOwnable is ISafeOwnableInternal , IOwnable {
function nomineeOwner ( ) external view returns (address ) ;
function acceptOwnership ( ) external ;
}
File 37 of 51: ISafeOwnableInternal.sol
pragma solidity ^0.8.8;
import { IOwnableInternal } from './IOwnableInternal.sol' ;
interface ISafeOwnableInternal is IOwnableInternal {
error SafeOwnable__NotNomineeOwner ( ) ;
}
File 38 of 51: ISolidStateDiamond.sol
pragma solidity ^0.8.8;
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 ;
}
File 39 of 51: LibSilksHorseDiamond.sol
pragma solidity ^0.8.9;
import {EnumerableSet } from "@solidstate/contracts/data/EnumerableSet.sol" ;
struct SeasonInfo {
uint256 seasonId;
string description;
bool paused;
bool valid;
}
struct PayoutTier {
uint256 tierId;
string description;
uint256 price;
uint256 maxPerTx;
uint256 payoutPct;
uint256 maxSupply;
bool paused;
bool valid;
}
enum MintMethod {
PURCHASE,
AIRDROP,
EXTERNAL_MINT
}
bytes32 constant CONTRACT_ADMIN_ROLE = keccak256 ("silks.contracts.roles.ContractAdminRole" );
bytes32 constant MINT_ADMIN_ROLE = keccak256 ("silks.contracts.roles.MintAdminRole" );
bytes32 constant HORSE_PURCHASING_PAUSED = keccak256 ('silks.contracts.paused.HorsePurchasing' );
error InvalidAddress (address _address ) ;
error InvalidSeason (uint256 _sent ) ;
error InvalidPayoutTier (uint256 _sent ) ;
error InvalidTokenId (uint256 _sent ) ;
error InvalidIntValue (string _reason, uint256 _sent, uint256 _expected ) ;
error InvalidStringValue (string _reason, string _sent, string _expected ) ;
error InvalidExternalMintAddress (address _sender ) ;
error MaxHorsesPerWalletExceeded (address _walletAddress ) ;
error PayoutTierMaxSupplyExceeded (uint256 _payoutTier ) ;
error MintFailed (string _reason, uint256 _seasonId, uint256 _payoutTier, uint256 _quantity, MintMethod _method, address _to ) ;
library LibSilksHorseDiamond {
bytes32 internal constant STORAGE_SLOT = keccak256 ('silks.contracts.storage.SilksHorseDiamond' );
struct Layout {
mapping (uint256 = > EnumerableSet.UintSet) seasonHorses;
mapping (uint256 = > SeasonInfo) seasonInfos;
mapping (uint256 = > PayoutTier) payoutTiers;
mapping (uint256 = > PayoutTier) horsePayoutTier;
mapping (uint256 = > EnumerableSet.UintSet) payoutTierHorses;
mapping (uint256 = > SeasonInfo) horseSeasonInfo;
mapping (address = > bool ) allowedExternalMintAddresses;
uint256 maxHorsesPerWallet;
uint256 nextAvailableTokenId;
}
function layout ( )
internal
pure
returns (
Layout storage l
) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
} File 40 of 51: Ownable.sol
pragma solidity ^0.8.8;
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);
}
}
File 41 of 51: OwnableInternal.sol
pragma solidity ^0.8.8;
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;
}
}
File 42 of 51: OwnableStorage.sol
pragma solidity ^0.8.8;
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
}
}
}
File 43 of 51: PausableInternal.sol
pragma solidity ^0.8.8;
import { IPausableInternal } from './IPausableInternal.sol' ;
import { PausableStorage } from './PausableStorage.sol' ;
abstract contract PausableInternal is IPausableInternal {
modifier whenNotPaused ( ) {
if (_paused()) revert Pausable__Paused();
_ ;
}
modifier whenPaused ( ) {
if (! _paused()) revert Pausable__NotPaused();
_ ;
}
function _paused ( ) internal view virtual returns (bool status ) {
status = PausableStorage.layout().paused;
}
function _pause ( ) internal virtual whenNotPaused {
PausableStorage.layout().paused = true ;
emit Paused(msg .sender );
}
function _unpause ( ) internal virtual whenPaused {
delete PausableStorage.layout().paused;
emit Unpaused(msg .sender );
}
}
File 44 of 51: PausableStorage.sol
pragma solidity ^0.8.8;
library PausableStorage {
struct Layout {
bool paused;
}
bytes32 internal constant STORAGE_SLOT =
keccak256 ('solidstate.contracts.storage.Pausable' );
function layout ( ) internal pure returns (Layout storage l ) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}
File 45 of 51: Proxy.sol
pragma solidity ^0.8.8;
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 ) ;
}
File 46 of 51: SafeOwnable.sol
pragma solidity ^0.8.8;
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);
}
}
File 47 of 51: SafeOwnableInternal.sol
pragma solidity ^0.8.8;
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;
}
}
File 48 of 51: SafeOwnableStorage.sol
pragma solidity ^0.8.8;
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
}
}
}
File 49 of 51: SilksHorseDiamond.sol
pragma solidity ^0.8.9;
import { AccessControlInternal } from "@solidstate/contracts/access/access_control/AccessControlInternal.sol" ;
import { AccessControlStorage } from "@solidstate/contracts/access/access_control/AccessControlStorage.sol" ;
import { ERC2981 } from "@solidstate/contracts/token/common/ERC2981/ERC2981.sol" ;
import { ERC2981Storage } from "@solidstate/contracts/token/common/ERC2981/ERC2981Storage.sol" ;
import { ERC721MetadataStorage } from "@solidstate/contracts/token/ERC721/metadata/ERC721MetadataStorage.sol" ;
import { PausableInternal } from "@solidstate/contracts/security/pausable/PausableInternal.sol" ;
import { SolidStateDiamond } from "@solidstate/contracts/proxy/diamond/SolidStateDiamond.sol" ;
import "./libraries/LibSilksHorseDiamond.sol" ;
contract SilksHorseDiamond is
AccessControlInternal ,
ERC2981 ,
PausableInternal ,
SolidStateDiamond
{
using AccessControlStorage for AccessControlStorage .Layout ;
constructor (
address _contractOwner,
string memory _tokenName,
string memory _tokenSymbol,
string memory _tokenBaseURI,
uint256 _startTokenId,
address _royaltyReceiver,
uint16 _royaltyBasePoints,
uint256 _maxHorsesPerWallet,
SeasonInfo[] memory _seasonInfos,
PayoutTier[] memory _payoutTiers
)
SolidStateDiamond ( )
{
ERC721MetadataStorage.layout().name = _tokenName;
ERC721MetadataStorage.layout().symbol = _tokenSymbol;
ERC721MetadataStorage.layout().baseURI = _tokenBaseURI;
ERC2981Storage.layout().defaultRoyaltyReceiver = _royaltyReceiver;
ERC2981Storage.layout().defaultRoyaltyBPS = _royaltyBasePoints;
_setOwner(_contractOwner);
_pause();
_grantRole(AccessControlStorage.DEFAULT_ADMIN_ROLE, _contractOwner);
_setRoleAdmin(CONTRACT_ADMIN_ROLE, AccessControlStorage.DEFAULT_ADMIN_ROLE);
_grantRole(CONTRACT_ADMIN_ROLE, _contractOwner);
_setRoleAdmin(MINT_ADMIN_ROLE, AccessControlStorage.DEFAULT_ADMIN_ROLE);
_grantRole(MINT_ADMIN_ROLE, _contractOwner);
LibSilksHorseDiamond.Layout storage lsh = LibSilksHorseDiamond.layout();
lsh.nextAvailableTokenId = _startTokenId;
lsh.maxHorsesPerWallet = _maxHorsesPerWallet;
for (uint256 i = 0 ; i < _seasonInfos.length ; i+ + ){
lsh.seasonInfos[_seasonInfos[i].seasonId] = _seasonInfos[i];
}
for (uint256 i = 0 ; i < _payoutTiers.length ; i+ + ){
lsh.payoutTiers[_payoutTiers[i].tierId] = _payoutTiers[i];
}
}
}
File 50 of 51: SolidStateDiamond.sol
pragma solidity ^0.8.8;
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 { ERC165Base , ERC165BaseStorage } from '../../introspection/ERC165/base/ERC165Base.sol' ;
import { DiamondBase } from './base/DiamondBase.sol' ;
import { DiamondFallback , IDiamondFallback } from './fallback/DiamondFallback.sol' ;
import { DiamondReadable , IDiamondReadable } from './readable/DiamondReadable.sol' ;
import { DiamondWritable , IDiamondWritable } 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+ + ] = IDiamondWritable.diamondCut.selector ;
_setSupportsInterface(type (IDiamondWritable).interfaceId , true );
selectors[selectorIndex+ + ] = IDiamondReadable.facets.selector ;
selectors[selectorIndex+ + ] = IDiamondReadable
.facetFunctionSelectors
.selector ;
selectors[selectorIndex+ + ] = IDiamondReadable.facetAddresses.selector ;
selectors[selectorIndex+ + ] = IDiamondReadable.facetAddress.selector ;
_setSupportsInterface(type (IDiamondReadable).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();
}
}
File 51 of 51: UintUtils.sol
pragma solidity ^0.8.8;
library UintUtils {
error UintUtils__InsufficientHexLength ( ) ;
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 ) internal pure returns (string memory ) {
if (value = = 0 ) {
return '0' ;
}
uint256 temp = value;
uint256 digits;
while (temp ! = 0 ) {
digits+ + ;
temp / = 10 ;
}
bytes memory buffer = new bytes (digits);
while (value ! = 0 ) {
digits - = 1 ;
buffer[digits] = bytes1 (uint8 (48 + uint256 (value % 10 )));
value / = 10 ;
}
return string (buffer);
}
function toHexString (uint256 value ) internal pure returns (string memory ) {
if (value = = 0 ) {
return '0x00' ;
}
uint256 length = 0 ;
for (uint256 temp = value; temp ! = 0 ; temp > > = 8 ) {
unchecked {
length+ + ;
}
}
return toHexString(value, length);
}
function toHexString (
uint256 value,
uint256 length
) internal pure returns (string memory ) {
bytes memory buffer = new bytes (2 * length + 2 );
buffer[0 ] = '0' ;
buffer[1 ] = 'x' ;
unchecked {
for (uint256 i = 2 * length + 1 ; i > 1 ; - - i) {
buffer[i] = HEX_SYMBOLS[value & 0xf ];
value > > = 4 ;
}
}
if (value ! = 0 ) revert UintUtils__InsufficientHexLength();
return string (buffer);
}
}
{
"compilationTarget" : {
"contracts/SilksHorseDiamond.sol" : "SilksHorseDiamond"
} ,
"evmVersion" : "paris" ,
"libraries" : { } ,
"metadata" : {
"bytecodeHash" : "ipfs"
} ,
"optimizer" : {
"enabled" : false ,
"runs" : 200
} ,
"remappings" : [ ]
} [{"inputs":[{"internalType":"address","name":"_contractOwner","type":"address"},{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"string","name":"_tokenSymbol","type":"string"},{"internalType":"string","name":"_tokenBaseURI","type":"string"},{"internalType":"uint256","name":"_startTokenId","type":"uint256"},{"internalType":"address","name":"_royaltyReceiver","type":"address"},{"internalType":"uint16","name":"_royaltyBasePoints","type":"uint16"},{"internalType":"uint256","name":"_maxHorsesPerWallet","type":"uint256"},{"components":[{"internalType":"uint256","name":"seasonId","type":"uint256"},{"internalType":"string","name":"description","type":"string"},{"internalType":"bool","name":"paused","type":"bool"},{"internalType":"bool","name":"valid","type":"bool"}],"internalType":"struct SeasonInfo[]","name":"_seasonInfos","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"tierId","type":"uint256"},{"internalType":"string","name":"description","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"maxPerTx","type":"uint256"},{"internalType":"uint256","name":"payoutPct","type":"uint256"},{"internalType":"uint256","name":"maxSupply","type":"uint256"},{"internalType":"bool","name":"paused","type":"bool"},{"internalType":"bool","name":"valid","type":"bool"}],"internalType":"struct PayoutTier[]","name":"_payoutTiers","type":"tuple[]"}],"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":"Pausable__NotPaused","type":"error"},{"inputs":[],"name":"Pausable__Paused","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 IDiamondWritableInternal.FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"indexed":false,"internalType":"struct IDiamondWritableInternal.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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"enum IDiamondWritableInternal.FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"selectors","type":"bytes4[]"}],"internalType":"struct IDiamondWritableInternal.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 IDiamondReadable.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":"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":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"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"}]