mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 19:26:33 +00:00
Fix .gitignore: stop tracking ignored files
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Implementation of the {IERC165} interface.
|
||||
*
|
||||
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
|
||||
* for the additional interface id that will be supported. For example:
|
||||
*
|
||||
* ```solidity
|
||||
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
||||
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
|
||||
*/
|
||||
abstract contract ERC165 is IERC165 {
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
||||
return interfaceId == type(IERC165).interfaceId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (utils/introspection/ERC165Checker.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Library used to query support of an interface declared via {IERC165}.
|
||||
*
|
||||
* Note that these functions return the actual result of the query: they do not
|
||||
* `revert` if an interface is not supported. It is up to the caller to decide
|
||||
* what to do in these cases.
|
||||
*/
|
||||
library ERC165Checker {
|
||||
// As per the EIP-165 spec, no interface should ever match 0xffffffff
|
||||
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
|
||||
|
||||
/**
|
||||
* @dev Returns true if `account` supports the {IERC165} interface.
|
||||
*/
|
||||
function supportsERC165(address account) internal view returns (bool) {
|
||||
// Any contract that implements ERC165 must explicitly indicate support of
|
||||
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
|
||||
return
|
||||
supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
|
||||
!supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if `account` supports the interface defined by
|
||||
* `interfaceId`. Support for {IERC165} itself is queried automatically.
|
||||
*
|
||||
* See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
|
||||
// query support of both ERC165 as per the spec and support of _interfaceId
|
||||
return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns a boolean array where each value corresponds to the
|
||||
* interfaces passed in and whether they're supported or not. This allows
|
||||
* you to batch check interfaces for a contract where your expectation
|
||||
* is that some interfaces may not be supported.
|
||||
*
|
||||
* See {IERC165-supportsInterface}.
|
||||
*
|
||||
* _Available since v3.4._
|
||||
*/
|
||||
function getSupportedInterfaces(
|
||||
address account,
|
||||
bytes4[] memory interfaceIds
|
||||
) internal view returns (bool[] memory) {
|
||||
// an array of booleans corresponding to interfaceIds and whether they're supported or not
|
||||
bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
|
||||
|
||||
// query support of ERC165 itself
|
||||
if (supportsERC165(account)) {
|
||||
// query support of each interface in interfaceIds
|
||||
for (uint256 i = 0; i < interfaceIds.length; i++) {
|
||||
interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return interfaceIdsSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if `account` supports all the interfaces defined in
|
||||
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
|
||||
*
|
||||
* Batch-querying can lead to gas savings by skipping repeated checks for
|
||||
* {IERC165} support.
|
||||
*
|
||||
* See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
|
||||
// query support of ERC165 itself
|
||||
if (!supportsERC165(account)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// query support of each interface in interfaceIds
|
||||
for (uint256 i = 0; i < interfaceIds.length; i++) {
|
||||
if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// all interfaces supported
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Query if a contract implements an interface, does not check ERC165 support
|
||||
* @param account The address of the contract to query for support of an interface
|
||||
* @param interfaceId The interface identifier, as specified in ERC-165
|
||||
* @return true if the contract at account indicates support of the interface with
|
||||
* identifier interfaceId, false otherwise
|
||||
* @dev Assumes that account contains a contract that supports ERC165, otherwise
|
||||
* the behavior of this method is undefined. This precondition can be checked
|
||||
* with {supportsERC165}.
|
||||
*
|
||||
* Some precompiled contracts will falsely indicate support for a given interface, so caution
|
||||
* should be exercised when using this function.
|
||||
*
|
||||
* Interface identification is specified in ERC-165.
|
||||
*/
|
||||
function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
|
||||
// prepare call
|
||||
bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
|
||||
|
||||
// perform static call
|
||||
bool success;
|
||||
uint256 returnSize;
|
||||
uint256 returnValue;
|
||||
assembly {
|
||||
success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
|
||||
returnSize := returndatasize()
|
||||
returnValue := mload(0x00)
|
||||
}
|
||||
|
||||
return success && returnSize >= 0x20 && returnValue > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Storage.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./ERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Storage based implementation of the {IERC165} interface.
|
||||
*
|
||||
* Contracts may inherit from this and call {_registerInterface} to declare
|
||||
* their support of an interface.
|
||||
*/
|
||||
abstract contract ERC165Storage is ERC165 {
|
||||
/**
|
||||
* @dev Mapping of interface ids to whether or not it's supported.
|
||||
*/
|
||||
mapping(bytes4 => bool) private _supportedInterfaces;
|
||||
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
||||
return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Registers the contract as an implementer of the interface defined by
|
||||
* `interfaceId`. Support of the actual ERC165 interface is automatic and
|
||||
* registering its interface id is not required.
|
||||
*
|
||||
* See {IERC165-supportsInterface}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
|
||||
*/
|
||||
function _registerInterface(bytes4 interfaceId) internal virtual {
|
||||
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
|
||||
_supportedInterfaces[interfaceId] = true;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (utils/introspection/ERC1820Implementer.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./IERC1820Implementer.sol";
|
||||
|
||||
/**
|
||||
* @dev Implementation of the {IERC1820Implementer} interface.
|
||||
*
|
||||
* Contracts may inherit from this and call {_registerInterfaceForAddress} to
|
||||
* declare their willingness to be implementers.
|
||||
* {IERC1820Registry-setInterfaceImplementer} should then be called for the
|
||||
* registration to be complete.
|
||||
*
|
||||
* CAUTION: This file is deprecated as of v4.9 and will be removed in the next major release.
|
||||
*/
|
||||
contract ERC1820Implementer is IERC1820Implementer {
|
||||
bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC");
|
||||
|
||||
mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces;
|
||||
|
||||
/**
|
||||
* @dev See {IERC1820Implementer-canImplementInterfaceForAddress}.
|
||||
*/
|
||||
function canImplementInterfaceForAddress(
|
||||
bytes32 interfaceHash,
|
||||
address account
|
||||
) public view virtual override returns (bytes32) {
|
||||
return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Declares the contract as willing to be an implementer of
|
||||
* `interfaceHash` for `account`.
|
||||
*
|
||||
* See {IERC1820Registry-setInterfaceImplementer} and
|
||||
* {IERC1820Registry-interfaceHash}.
|
||||
*/
|
||||
function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual {
|
||||
_supportedInterfaces[interfaceHash][account] = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
/**
|
||||
* @dev Interface of the ERC165 standard, as defined in the
|
||||
* https://eips.ethereum.org/EIPS/eip-165[EIP].
|
||||
*
|
||||
* Implementers can declare support of contract interfaces, which can then be
|
||||
* queried by others ({ERC165Checker}).
|
||||
*
|
||||
* For an implementation, see {ERC165}.
|
||||
*/
|
||||
interface IERC165 {
|
||||
/**
|
||||
* @dev Returns true if this contract implements the interface defined by
|
||||
* `interfaceId`. See the corresponding
|
||||
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
|
||||
* to learn more about how these ids are created.
|
||||
*
|
||||
* This function call must use less than 30 000 gas.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC1820Implementer.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
/**
|
||||
* @dev Interface for an ERC1820 implementer, as defined in the
|
||||
* https://eips.ethereum.org/EIPS/eip-1820#interface-implementation-erc1820implementerinterface[EIP].
|
||||
* Used by contracts that will be registered as implementers in the
|
||||
* {IERC1820Registry}.
|
||||
*/
|
||||
interface IERC1820Implementer {
|
||||
/**
|
||||
* @dev Returns a special value (`ERC1820_ACCEPT_MAGIC`) if this contract
|
||||
* implements `interfaceHash` for `account`.
|
||||
*
|
||||
* See {IERC1820Registry-setInterfaceImplementer}.
|
||||
*/
|
||||
function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view returns (bytes32);
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.9.0) (utils/introspection/IERC1820Registry.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
/**
|
||||
* @dev Interface of the global ERC1820 Registry, as defined in the
|
||||
* https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register
|
||||
* implementers for interfaces in this registry, as well as query support.
|
||||
*
|
||||
* Implementers may be shared by multiple accounts, and can also implement more
|
||||
* than a single interface for each account. Contracts can implement interfaces
|
||||
* for themselves, but externally-owned accounts (EOA) must delegate this to a
|
||||
* contract.
|
||||
*
|
||||
* {IERC165} interfaces can also be queried via the registry.
|
||||
*
|
||||
* For an in-depth explanation and source code analysis, see the EIP text.
|
||||
*/
|
||||
interface IERC1820Registry {
|
||||
event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer);
|
||||
|
||||
event ManagerChanged(address indexed account, address indexed newManager);
|
||||
|
||||
/**
|
||||
* @dev Sets `newManager` as the manager for `account`. A manager of an
|
||||
* account is able to set interface implementers for it.
|
||||
*
|
||||
* By default, each account is its own manager. Passing a value of `0x0` in
|
||||
* `newManager` will reset the manager to this initial state.
|
||||
*
|
||||
* Emits a {ManagerChanged} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must be the current manager for `account`.
|
||||
*/
|
||||
function setManager(address account, address newManager) external;
|
||||
|
||||
/**
|
||||
* @dev Returns the manager for `account`.
|
||||
*
|
||||
* See {setManager}.
|
||||
*/
|
||||
function getManager(address account) external view returns (address);
|
||||
|
||||
/**
|
||||
* @dev Sets the `implementer` contract as ``account``'s implementer for
|
||||
* `interfaceHash`.
|
||||
*
|
||||
* `account` being the zero address is an alias for the caller's address.
|
||||
* The zero address can also be used in `implementer` to remove an old one.
|
||||
*
|
||||
* See {interfaceHash} to learn how these are created.
|
||||
*
|
||||
* Emits an {InterfaceImplementerSet} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must be the current manager for `account`.
|
||||
* - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not
|
||||
* end in 28 zeroes).
|
||||
* - `implementer` must implement {IERC1820Implementer} and return true when
|
||||
* queried for support, unless `implementer` is the caller. See
|
||||
* {IERC1820Implementer-canImplementInterfaceForAddress}.
|
||||
*/
|
||||
function setInterfaceImplementer(address account, bytes32 _interfaceHash, address implementer) external;
|
||||
|
||||
/**
|
||||
* @dev Returns the implementer of `interfaceHash` for `account`. If no such
|
||||
* implementer is registered, returns the zero address.
|
||||
*
|
||||
* If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28
|
||||
* zeroes), `account` will be queried for support of it.
|
||||
*
|
||||
* `account` being the zero address is an alias for the caller's address.
|
||||
*/
|
||||
function getInterfaceImplementer(address account, bytes32 _interfaceHash) external view returns (address);
|
||||
|
||||
/**
|
||||
* @dev Returns the interface hash for an `interfaceName`, as defined in the
|
||||
* corresponding
|
||||
* https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP].
|
||||
*/
|
||||
function interfaceHash(string calldata interfaceName) external pure returns (bytes32);
|
||||
|
||||
/**
|
||||
* @notice Updates the cache with whether the contract implements an ERC165 interface or not.
|
||||
* @param account Address of the contract for which to update the cache.
|
||||
* @param interfaceId ERC165 interface for which to update the cache.
|
||||
*/
|
||||
function updateERC165Cache(address account, bytes4 interfaceId) external;
|
||||
|
||||
/**
|
||||
* @notice Checks whether a contract implements an ERC165 interface or not.
|
||||
* If the result is not cached a direct lookup on the contract address is performed.
|
||||
* If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling
|
||||
* {updateERC165Cache} with the contract address.
|
||||
* @param account Address of the contract to check.
|
||||
* @param interfaceId ERC165 interface to check.
|
||||
* @return True if `account` implements `interfaceId`, false otherwise.
|
||||
*/
|
||||
function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool);
|
||||
|
||||
/**
|
||||
* @notice Checks whether a contract implements an ERC165 interface or not without using or updating the cache.
|
||||
* @param account Address of the contract to check.
|
||||
* @param interfaceId ERC165 interface to check.
|
||||
* @return True if `account` implements `interfaceId`, false otherwise.
|
||||
*/
|
||||
function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool);
|
||||
}
|
||||
Reference in New Issue
Block a user